首页 > 解决方案 > 反应路由:使用 id_token 开关无法按预期工作

问题描述

我在 React 中使用以下路由语句:

  <Switch>
     <Redirect from="/start" to="/xyz" />                            
     <Route path="/xyz" component={MyTab} />
     <Route exact path="**" component={NotFound} />
  </Switch>

现在,在我的浏览器中,我使用哈希片段转到/start路径。我观察到的是:

为什么以及如何使第二个案例最终出现在 MyTab 中?

标签: reactjsoauth-2.0react-routerurl-routingaccess-token

解决方案


以下内容应该适合您:

 <Switch>
     <Route path="/start" component={MyTab} />                          
     <Route path="/xyz" component={MyTab} />
     <Route component={NotFound} />
  </Switch>

推荐阅读