我有一个带有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}`)
);当我这样做时,我从应用程序接口收到一个错误,我想导航到当前路由作为查询字符串参数的登录页面,模板抛出以下错误:[ion-router] the path does not match any route。
如何将querystring与ion-router一起使用?
发布于 2020-06-06 00:32:53
IMO它目前是离子领域的一个bug (见https://github.com/ionic-team/ionic/issues/19707)。
为了暂时解决这个问题,您可能可以使用
navCtrl.push('/login');
history.replaceState(undefined, '', `?redirect=${window.location.pathname}`);https://stackoverflow.com/questions/62214428
复制相似问题