[英]Angular 9 - Convoluted child/parent navigation
I've just completely stuck with the following.我完全坚持以下几点。 I have some set of routes with two different parent layouts.我有一些具有两种不同父布局的路线。
routing.module.ts路由.module.ts
{
path: '',
component: FrameworkComponent,
children: [
{
path: 'products',
component: ProductListingPageComponent,
canActivate: [EnsureAuthenticated]
},
{
path: 'categories',
component: CategoryListingPageComponent,
canActivate: [EnsureAuthenticated]
}
]
},
{
path: '',
component: AppComponent,
children: [
{
path: 'login',
component: LoginPageComponent
},
{
path: 'register',
component: RegistrationPageComponent
}
]
}
So being on LoginPageComponents I just would like to navigate to /products
path (in case of success during logging in)因此,在 LoginPageComponents 上,我只想导航到/products
路径(以防登录成功)
login-page.component.ts登录页面.component.ts
this.authService.logIn(this.credentials)
.then(_ => this.router.navigateByUrl('/products'))
.catch(this.handleLoginError.bind(this));
As a result I get nothing.结果我什么也得不到。 Just a request flies to a server and I see successful login and nothing more - no errors etc.只是一个请求飞到服务器,我看到成功登录,仅此而已 - 没有错误等。
Could you please advise?您能否提一些建议?
Have you tried checking the response that you're getting?您是否尝试过检查您收到的回复?
this.authService.logIn(this.credentials)
.then(res => {
console.log(res);
this.router.navigateByUrl('/products');
}).catch(this.handleLoginError.bind(this));
After thousands of trial and errors I've found the solution.经过数千次试验和错误,我找到了解决方案。 An issue was in canActivate
property. canActivate
属性中存在问题。 It checks whether login token is in place and I had forgotten to set this token during login previously.它检查登录令牌是否到位,并且我之前忘记在登录期间设置此令牌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.