Basename not working properly

后端 未结 3 2047
闹比i
闹比i 2021-02-20 03:20

I\'m attempting to use a basename with react-router as documented on the react-router docs. This is due to base href being deprecated.

Here is what I have now:

3条回答
  •  时光取名叫无心
    2021-02-20 03:43

    Using BrowserRouter

    helpers/history.js

    import { createBrowserHistory } from "history";
    export default createBrowserHistory();
    

    index.js

    import {BrowserRouter as Router} from "react-router-dom";
    import history from "helpers/history";
    .....
    
      
    ...
    
    

    Using Router

    helpers/history.js

    import { createBrowserHistory } from "history";
    export default createBrowserHistory({ basename: '/app' });
    

    index.js

    import {Router} from "react-router-dom";
    import history from "helpers/history";
    ....
    
      
    ...
    
    

提交回复
热议问题