umi#useLocation TypeScript Examples

The following examples show how to use umi#useLocation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: _layout.tsx    From bext with MIT License 6 votes vote down vote up
ToolLayout: FC = ({ children }) => {
  const location = useLocation();
  const toolName = useMemo(() => {
    const match = location.pathname.match(/\/tool\/(.*)/)?.[1];
    return TOOLS.find((tool) => match?.startsWith(tool.path))?.name || '工具';
  }, [location.pathname]);

  useTitle(toolName);

  return <>{children || null}</>;
}
Example #2
Source File: header.tsx    From bext with MIT License 5 votes vote down vote up
NormalHeader = () => {
  const location = useLocation();
  const historyReplace = useHistoryReplace();
  const route = `/${location.pathname.split('/')[1]}`;

  const onLinkClick = useCallback(
    (key: string) => {
      historyReplace(key);
    },
    [history],
  );

  return (
    <>
      <header className="px-6 flex items-center">
        <span
          className="text-xl font-extralight mr-4"
          onClick={() =>
            historyReplace('/', {
              previewId: undefined,
              previewMeta: undefined,
            })
          }
        >
          Bext
        </span>
        <Pivot
          selectedKey={route}
          onLinkClick={(item) => onLinkClick(item?.props.itemKey || '/')}
        >
          <PivotItem headerText="首页" itemKey="/" />
          <PivotItem headerText="脚本" itemKey="/meta" />
          <PivotItem headerText="工具" itemKey="/tool" />
          <PivotItem headerText="开发" itemKey="/dev" />
          <PivotItem headerText="更多" itemKey="/more" />
        </Pivot>
      </header>
    </>
  );
}