我看到了很多关于如何在 SPA 中创建未找到页面的路由的解决方案,但似乎无法为也使用单独页面(如登录)的 SPA 找到任何内容。
例如:
<Router>
<Switch>
<Route path="/login" component={Login} />
<Route path="/" component={Main} />
** a catch all route wouldn't work here **
</Switch>
</Router>
包罗万象的路线在上面不起作用,<Route component={NotFound} />
因为路径将从path='/'
. 如果我切换到exact path='/'
,则无法localhost:3000/users
从用户登录时需要的 URL访问。
Main
:
<Switch>
<div className="someclass">
<Header />
<Route exact path='users' component={Users} />
<Footer />
</div>
<Route component={NotFound} /> . ** This also doesn't work here **
</Switch>