React history.push() is updating url but not navigating to it in browser

后端 未结 7 869
误落风尘
误落风尘 2020-12-13 16:50

I\'ve read many things about react-router v4 and the npm history library to this point, but none seems to be helping me.

My code is functioning as expected up to t

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 17:34

    import Router from react-router-dom not BrowserRouter

    // index.js
    
        import React from "react";
        import ReactDOM from "react-dom";
        import App from "./App";
        import { Router } from "react-router-dom";
        import history from './utils/history'
    
    
        ReactDOM.render(
          
            
          ,
          document.getElementById("root"));
    
        serviceWorker.register();
    
    
    // history.js 
    
    import { createBrowserHistory } from 'history';
    
    export default createBrowserHistory();
    

    on other components that you need to navigate import history and push

    import History from '../utils/history'
    
    History.push('/home')
    
    

提交回复
热议问题