【发布时间】:2018-12-10 03:38:34
【问题描述】:
我看到了很多关于如何在 SPA 中创建找不到页面的路由的解决方案,但似乎无法为也使用单独页面(如登录)的 SPA 找到任何东西。
例如:
<Router>
<Switch>
<Route path="/login" component={Login} />
<Route path="/" component={Main} />
** a catch all route wouldn't work here **
</Switch>
</Router>
catch-all 路径不适用于<Route component={NotFound} /> 之类的东西,因为路径会在来自path='/' 的任何地方触发。如果我切换到exact path='/',那么我将无法从用户登录时需要的URL 访问localhost:3000/users。
Main:
<Switch>
<div className="someclass">
<Header />
<Route exact path='users' component={Users} />
<Footer />
</div>
<Route component={NotFound} /> . ** This also doesn't work here **
</Switch>
【问题讨论】:
标签: reactjs react-router