【发布时间】:2021-12-10 05:30:17
【问题描述】:
我在底部的每一页上都得到not found 页面。
我已将navbar 放在login & signup 之后,因此它在登录和注册页面上不可见。
我在按钮的每个页面中都找不到页面。我不确定它为什么会出现。
<Router>
<Switch>
<MyRoute
restricted={userid}
exactly
path="/login"
component={LoginSignupPage}
/>
<MyNavBar>
<PrivateRoute
exactly
path="/"
component={HomePage}
/>
<MyRoute
restricted={false}
exactly
path="/user/:userId"
component={UserProfilePage}
/>
<MyRoute
restricted={false}
component={NotFoundPage}
/>
</MyNavBar>
</Switch>
</Router>
MyRoute.tsx
<Route {...rest} render={props => (
restricted ?
<Redirect to="/" />
: <Component {...props} />
)} />
React 路由器 dom 版本
"react-router-dom": "^5.3.0",
【问题讨论】:
-
你用的是哪个 react-router-dom 版本?
-
我正在使用“react-router-dom”:“^5.3.0”@ParthNavadiya
-
react-router-dom不会导出Router,而是导出BrowserRouter,因此您需要从“react-router-dom”导入{ BrowserRouter as Router }。 -
我已经完成了。我刚刚在
404 page遇到了每一页都出现的问题。 @ParthNavadiya -
是的,我通过用导航栏包裹每个组件来修复。
标签: reactjs react-router react-router-dom