Programmatically navigate using react router

后端 未结 30 2394
無奈伤痛
無奈伤痛 2020-11-21 05:18

With react-router I can use the Link element to create links which are natively handled by react router.

I see internally it calls t

30条回答
  •  遥遥无期
    2020-11-21 05:23

    with React-Router v4 on the horizon, there is now a new way of doing this.

    import { MemoryRouter, BrowserRouter } from 'react-router';
    
    const navigator = global && global.navigator && global.navigator.userAgent;
    const hasWindow = typeof window !== 'undefined';
    const isBrowser = typeof navigator !== 'undefined' && navigator.indexOf('Node.js') === -1;
    const Router = isBrowser ? BrowserRouter : MemoryRouter;
    
    
    

    react-lego is an example app that shows how to use/update react-router and it includes example functional tests which navigate the app.

提交回复
热议问题