Basename not working properly

后端 未结 3 1991
闹比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:58

    I solved it by using:

    import { Router, useRouterHistory } from 'react-router'
    import createBrowserHistory from 'history/lib/createBrowserHistory'
    
    const history = useRouterHistory(createBrowserHistory)({
        basename: '/',
    })
    
    
    

    I think the issue was different versions of the history package. react-router@2.2.4 uses history@2.1.2, while history is already at 4.5.1. So make sure you install the correct version of the history package.

提交回复
热议问题