离子路由器中的查询字符串支持(带有StencilJs)

问题描述 投票:0回答:2

我有一个使用以下路由设置的带有Ionic Web组件的StencilJS应用:

<ion-router useHash={false}>
  <ion-route url="/home" component="page-home"/>
  <ion-route url="/login" component="page-login"/>
  <ion-route url="/main" component="page-main">
</ion-router>

[当我从api收到401错误时,我想使用当前url作为重定向querystring参数来重定向到登录页面(以便将用户重定向回他的来源),如下所示:] >

const navCtrl: HTMLIonRouterElement = document.querySelector("ion-router");
fetch('https://someapi.com/users/1').then(
  res => navCtrl.push('/main'),
  err => navCtrl.push(`/login?redirect=${window.location.pathname}`)
);

[执行此操作时,我从api收到错误,并且我想使用当前路径作为querystring参数导航到登录页面,Stencil引发以下错误:[ion-router] the path does not match any route

如何将查询字符串与离子路由器一起使用?

我有一个使用以下路由设置的带有Ionic Web组件的StencilJS应用:

ionic-framework stenciljs ionic5
2个回答
0
投票

IMO,目前是Ionic中的错误(请参阅https://github.com/ionic-team/ionic/issues/19707


0
投票

感谢朝着正确的方向前进!您提供的代码未更改网址,因为navCtr.push返回了Promise。您必须等待它完成才能更改状态。我最终得到了这个可行的解决方法:

© www.soinside.com 2019 - 2024. All rights reserved.