History

history hooks

npm (scoped)

源码 Code

@spax/history

安装 Install

$ yarn add @spax/history

使用 Usage

import { useLocation, usePathname, useSearch, useHash } from "@spax/history";

// location: /#/login?name=joe#foo=bar

function MyFunctionalComponent(props: any) {
  const [location, navigate] = useLocation();
  const [pathname, setPathname] = usePathname();
  const [search, setSearch] = useSearch();
  const [hash, setHash] = useHash();

  console.log(location);
  // => { pathname: "/login", search: "name=joe", hash: "foo=bar"}

  console.log(pathname);
  // => "/login"

  console.log(search);
  // => { name: "joe" }

  console.log(hash);
  // => { foo: "bar" }
}

results matching ""

    No results matching ""