【问题标题】:React routing: Switch not working as expected with id_token反应路由:使用 id_token 开关无法按预期工作
【发布时间】:2021-01-18 06:20:49
【问题描述】:

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

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

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

  • 当哈希片段只有状态时 (例如http://localhost:3000/start#state=ABC),我最终在 MyTab,正如预期的那样。
  • 当哈希片段同时具有 stateid_token(例如http://localhost:3000/start#state=ABC&amp;id_token=PQR),我最终进入 未找到,与预期不同

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

【问题讨论】:

    标签: reactjs oauth-2.0 react-router url-routing access-token


    【解决方案1】:

    以下内容应该适合您:

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

    【讨论】:

    • 不,它没有!无论如何,我想要这个重定向,而不是路由。
    猜你喜欢
    • 2019-05-27
    • 1970-01-01
    • 2021-10-03
    • 2016-07-09
    • 2019-08-09
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多