如何检查递归路径 Url 是否在反应路由器中
how to check the recursive path Url is in react router or not
如何检查递归路径是否在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>
在我的浏览器中,如果我输入错误 url (http://0.0.0.0:3000/dgdfg),它会将我带到 PageNotFound
但是,如果我给 (http://0.0.0.0:3000/signup/dgdfg) 它不会带我到 PageNotFound
组件,它会显示空白页。如何使用 react router v4
解决这个问题
如果您将注册路径更改为准确的路径,将导致页面未找到答案。这是因为没有 "exact" 页面将解析为您的 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>
如何检查递归路径是否在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>
在我的浏览器中,如果我输入错误 url (http://0.0.0.0:3000/dgdfg),它会将我带到 PageNotFound
但是,如果我给 (http://0.0.0.0:3000/signup/dgdfg) 它不会带我到 PageNotFound
组件,它会显示空白页。如何使用 react router v4
如果您将注册路径更改为准确的路径,将导致页面未找到答案。这是因为没有 "exact" 页面将解析为您的 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>