我有这条路线:
const AppRouter = () => (
<Router history={history}>
<div>
<Switch>
<Route path='/' component={LoginPage} exact={true} />
</Switch>
</div>
</Router>
);
它仅在我将 Route path 设置为空字符串时才有效''
但是,日志history.location.pathname
显示/
它在 localhost:3000 上运行
我注意到这个有效:
<Route path=':3000/' component={LoginPage} exact={false} />
您也不必在“localhost:3000”之后的浏览器窗口中包含“/”。
import React from 'react'
import { BrowserRouter, Route, Switch } from "react-router-dom";
import ComponentName from './ComponentName';
const Router = () => {
<BrowserRouter>
<Switch>
<Route exact path="/" component={ComponentName}/>
</Switch>
</BrowserRouter>
}
export default Router;
之后将路由器组件导入 App.js。
import Router from './Router';
function App() {
return <Router />
}
export default App;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句