history#createBrowserHistory TypeScript Examples

The following examples show how to use history#createBrowserHistory. 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: history.ts    From easy-email with MIT License 6 votes vote down vote up
history = createBrowserHistory({
  getUserConfirmation(message, callback) {
    if (ConfirmBeforeLeavePage.confirmBeforeLeave) {
      ConfirmBeforeLeavePage.confirmBeforeLeave(message, callback);
    } else {
      callback(window.confirm(message));
    }
  },
})
Example #2
Source File: history.ts    From next-core with GNU General Public License v3.0 6 votes vote down vote up
/** @internal */
export function createHistory(): PluginHistory {
  const browserHistory = createBrowserHistory({
    basename: getBasePath().replace(/\/$/, ""),
  });
  Object.assign(browserHistory, historyExtended(browserHistory));
  history = browserHistory as PluginHistory;
  return history;
}
Example #3
Source File: store.ts    From lightning-terminal with MIT License 6 votes vote down vote up
createStore = (grpcClient?: GrpcClient, appStorage?: AppStorage) => {
  const grpc = grpcClient || new GrpcClient();
  // Resolve api requests with sample data when running client in develop mode.
  grpc.useSampleData = USE_SAMPLE_DATA;

  const storage = appStorage || new AppStorage();
  const lndApi = new LndApi(grpc);
  const loopApi = new LoopApi(grpc);
  const poolApi = new PoolApi(grpc);
  const litApi = new LitApi(grpc);
  const csv = new CsvExporter();
  const history = createBrowserHistory();

  const store = new Store(
    lndApi,
    loopApi,
    poolApi,
    litApi,
    storage,
    history,
    csv,
    actionLog,
  );

  // initialize the store immediately to fetch API data, except when running unit tests
  if (!IS_TEST) store.init();

  // in dev env, make the store accessible via the browser DevTools console
  if (IS_DEV) (global as any).store = store;

  return store;
}
Example #4
Source File: history-provider.ts    From malagu with MIT License 6 votes vote down vote up
constructor(
        @Value('malagu.react.history') protected readonly historyOptions: any
    ) {
        const historyCreatorMap: { [key: string]: any } = {
            hash: createHashHistory,
            browser: createBrowserHistory,
            memory: createMemoryHistory
        };
        if (this.historyOptions) {
            const { type, ...options } = historyOptions;
            const create = historyCreatorMap[type] || createHashHistory;
            this.history = create(options);
        } else {
            this.history = createHashHistory();
        }

    }
Example #5
Source File: SpfxPnpLoggingWebPart.ts    From SPFx with Mozilla Public License 2.0 6 votes vote down vote up
public render(): void {

    const browserHistory = createBrowserHistory({ basename: '' });
    var reactPlugin = new ReactPlugin();
    var appInsights = new ApplicationInsights({
        config: {
            // instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE',
            instrumentationKey: '6c0f2fd6-76a0-4671-9fad-e3c75ee02901',
            extensions: [reactPlugin],
            extensionConfig: {
              [reactPlugin.identifier]: { history: browserHistory }
            }
        }
    });
    appInsights.loadAppInsights();


    const element: React.ReactElement<ISpfxPnpLoggingProps> = React.createElement(
      SpfxPnpLogging,
      {
        description: this.properties.description,
        context:this.context
      }
    );

    ReactDom.render(element, this.domElement);
  }
Example #6
Source File: AppInsights.ts    From SPFx with Mozilla Public License 2.0 6 votes vote down vote up
ai = new ApplicationInsights({
    config: {
        instrumentationKey: '6c0f2fd6-76a0-4671-9fad-e3c75ee02901',
        extensions: [reactPlugin],
        extensionConfig: {
            [reactPlugin.identifier]: { history: createBrowserHistory }
        }
    }
})
Example #7
Source File: ApplicationStoreTestUtils.ts    From legend-studio with Apache License 2.0 6 votes vote down vote up
TEST__getTestApplicationStore = <
  T extends LegendApplicationConfig,
>(
  config: T,
  pluginManager: LegendApplicationPluginManager,
): ApplicationStore<T> =>
  new ApplicationStore(
    config,
    new WebApplicationNavigator(createBrowserHistory()),
    pluginManager,
  )
Example #8
Source File: Flow.test.tsx    From glific-frontend with GNU Affero General Public License v3.0 6 votes vote down vote up
it('should edit the flow', async () => {
  const history: any = createBrowserHistory();
  history.push({ pathname: `/flow/1/edit` });

  const editFlow = (match: any) => (
    <MockedProvider mocks={mocks} addTypename={false}>
      <Router history={history}>
        <Flow match={match} />
      </Router>
    </MockedProvider>
  );
  const { container, getByTestId } = render(editFlow({ params: { id: 1 } }));
  await waitFor(() => {});
});
Example #9
Source File: BasicLayout.tsx    From vite-react-ts with MIT License 6 votes vote down vote up
BasicLayout: React.FC<{ route: IRouteConfig }> = ({ route }) => {
  const history = createBrowserHistory();

  if (!localStorage.getItem('vite-react-ts-antd-token')) {
    history.push('/user/login');
  }

  return (
    <Layout>
      <MyMenu />
      <Layout>
        <MyHeader />
        <Content style={{ height: 'calc(100vh - 60px)' }}>
          {renderRoutes(route.routes)}
        </Content>
      </Layout>
    </Layout>
  );
}
Example #10
Source File: Authority.tsx    From vite-react-ts with MIT License 6 votes vote down vote up
Authority: React.FC = ({ children }) => {
  const history = createBrowserHistory();
  // const user = useStore((state) => state.user);
  // console.log('Authority', user);

  if (!localStorage.getItem('vite-react-ts-antd-token')) {
    history.push('/user/login');
  }
  // if (!user?.token) {
  //   history.push('/user/login');
  // }

  return <>{children}</>;
}
Example #11
Source File: index.tsx    From vite-react-ts with MIT License 6 votes vote down vote up
Header: React.FC = () => {
  const [openKeys, setOpenKeys] = useState<string[]>([]);
  const [selectedKeys, setSelectedKeys] = useState<string[]>([]);
  const sysRoutes = FilterRoutes(routes);
  const history = createBrowserHistory();

  // 路由监听
  useEffect(() => {
    const pathname = history.location.pathname;
    const match = matchRoutes(sysRoutes, pathname);

    if (match?.length) {
      setOpenKeys(match.map((n) => n.route.path));
      setSelectedKeys([match[0].route.path]);
    }
  }, [history.location.pathname]);

  return (
    <Sider>
      <div className={cls.menu_logo}>
        <Typography.Title className={cls.logo_title} level={5}>
          Logo
        </Typography.Title>
      </div>
      <Menu theme="dark" mode="inline" openKeys={openKeys} selectedKeys={selectedKeys}>
        {sysRoutes.map((item) => (
          <Menu.Item key={item.path}>
            <Link to={item.path}>{item.title}</Link>
          </Menu.Item>
        ))}
      </Menu>
    </Sider>
  );
}
Example #12
Source File: RoconRoot.tsx    From rocon with MIT License 6 votes vote down vote up
RoconRoot: React.FC<RoconRootProps> = memo((props) => {
  const history = useMemo(
    () => props.history || createBrowserHistory(),
    [props.history]
  );

  const historyContextValue = useMemo(() => {
    return {
      history,
    };
  }, [history]);

  const [location, setLocation] = useState<Location>(history.location);

  useEffect(() => {
    // this `setLocation` handles the case where location is changed after above `history.location` is calculated
    setLocation(history.location);
    return history.listen((state) => {
      setLocation(state.location);
    });
  }, [history]);

  return (
    <HistoryContext.Provider value={historyContextValue}>
      <LocationContext.Provider value={location}>
        {props.children}
      </LocationContext.Provider>
    </HistoryContext.Provider>
  );
})
Example #13
Source File: Flow.test.tsx    From glific-frontend with GNU Affero General Public License v3.0 6 votes vote down vote up
it('should create copy of flow', async () => {
  const history: any = createBrowserHistory();
  history.push({ pathname: `/flow/1/edit`, state: 'copy' });

  const copyFlow = (match: any) => (
    <MockedProvider mocks={mocks} addTypename={false}>
      <Router history={history}>
        <Flow match={match} />
      </Router>
    </MockedProvider>
  );

  const { container, getByTestId } = render(copyFlow({ params: { id: 1 } }));
  await waitFor(() => {
    expect(container.querySelector('input[name="name"]')?.value).toBe('Copy of Help');
  });

  fireEvent.change(container.querySelector('input[name="keywords"]'), {
    target: { value: 'help, activity' },
  });
  const button = getByTestId('submitActionButton');
  fireEvent.click(button);
  await waitFor(() => {
    // error if a keyword with same flow already exists
    // expect(getByTestId('dialogTitle')).toBeInTheDocument();
    // expect(screen.getByTestId('dialogTitle')).toThrow(
    //   'The keyword `help` was already used in the `Help Workflow` Flow.'
    // );
  });
});
Example #14
Source File: configureStore.ts    From tezos-link with Apache License 2.0 5 votes vote down vote up
history = createBrowserHistory()
Example #15
Source File: history.ts    From viewer with MIT License 5 votes vote down vote up
history = createBrowserHistory()
Example #16
Source File: App.tsx    From foodie with MIT License 5 votes vote down vote up
history = createBrowserHistory()
Example #17
Source File: Toolbar.test.tsx    From kfp-tekton-backend with Apache License 2.0 5 votes vote down vote up
history = createBrowserHistory({})
Example #18
Source File: store.ts    From mamori-i-japan-admin-panel with BSD 2-Clause "Simplified" License 5 votes vote down vote up
history = createBrowserHistory()
Example #19
Source File: history.ts    From calendar-hack with MIT License 5 votes vote down vote up
history = createBrowserHistory()
Example #20
Source File: BrowserHistory.ts    From whiteboard-demo with MIT License 5 votes vote down vote up
history = createBrowserHistory()
Example #21
Source File: index.tsx    From nouns-monorepo with GNU General Public License v3.0 5 votes vote down vote up
history = createBrowserHistory()
Example #22
Source File: App.store.tsx    From tezos-academy with MIT License 5 votes vote down vote up
history = createBrowserHistory()
Example #23
Source File: create-store.ts    From anthem with Apache License 2.0 5 votes vote down vote up
history = createBrowserHistory()
Example #24
Source File: router-history.ts    From querybook with Apache License 2.0 5 votes vote down vote up
history = createBrowserHistory({
    /* pass a configuration object here if needed */
})
Example #25
Source File: routing.tsx    From knboard with MIT License 5 votes vote down vote up
history = createBrowserHistory()
Example #26
Source File: store.ts    From rusty-chat with MIT License 5 votes vote down vote up
history = createBrowserHistory()
Example #27
Source File: history.ts    From projectboard with MIT License 5 votes vote down vote up
history = createBrowserHistory()
Example #28
Source File: i18n.ts    From covid-19 with MIT License 5 votes vote down vote up
history = createBrowserHistory()
Example #29
Source File: app.tsx    From caritas-onlineBeratung-frontend with GNU Affero General Public License v3.0 5 votes vote down vote up
history = createBrowserHistory()