【问题标题】:how to check the recursive path Url is in react router or not如何检查递归路径Url是否在反应路由器中
【发布时间】:2019-04-16 08:35:40
【问题描述】:

如何检查递归路径是否在react router中,这个

import { Switch, Route, Redirect } from 'react-router-dom';
<Switch>
    <Route exact path="/" component={SignIn} />
    <Route path="/signup" component={SignUp} />
    <Route path="/forget-password" component={ForgetPasswordPage} />
    <Route path="/reset-password" component={ResetPasswordPage} />
    <Route component={PageNotFound} />
</Switch>

如果我在我的浏览器中输入错误的网址 (http://0.0.0.0:3000/dgdfg),它会将我带到 PageNotFound 但是,如果我给(http://0.0.0.0:3000/signup/dgdfg)它不会带我去PageNotFound 组件,它会向我显示空白页。如何使用 react router v4 解决这个问题

【问题讨论】:

  • 如果你使用exact path= 而不是path 会怎样?

标签: reactjs react-router react-router-dom


【解决方案1】:

如果您将注册路径更改为精确,则会导致“找不到页面”答案。这是因为没有“确切”的页面解析为您的 SignUp 组件,因为它实际上在路径中有 /signup。

import { Switch, Route, Redirect } from 'react-router-dom';
<Switch>
   <Route exact path="/" component={SignIn} />
   <Route exact path="/signup" component={SignUp} />
   <Route path="/forget-password" component={ForgetPasswordPage} />
   <Route path="/reset-password" component={ResetPasswordPage} />
   <Route component={PageNotFound} />
</Switch>

【讨论】:

    猜你喜欢
    • 2018-08-21
    • 1970-01-01
    • 2016-07-08
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 2022-11-14
    • 1970-01-01
    相关资源
    最近更新 更多