P粉0870748972023-08-28 16:11:51
If you want to use
, it gives you access to the history object, allowing you to change the page via history.push('/my-path')
code> directly Method from js. You will face the problem that BrowserRouter has no history
property available, and Router has no basename
available.
The solution is as follows:
const App: React.FC = () => { // do not put a slash at the end of the basename value. const history = createBrowserHistory({ basename: '/your-base-name' }); return <Router history={history}> ... </Router>; }
https://reacttraining.com/react-router/web/ api/BrowserRouter/basename-string
P粉6474494442023-08-28 00:10:44
Using the latest react router (v4) you can do this easily
<BrowserRouter basename="/calendar"> <Link to="/today"/> // renders <a href="/calendar/today"> </BrowserRouter>