angular - Angular 9 - 复杂的子/父导航
问题描述
我完全坚持以下几点。我有一些具有两种不同父布局的路线。
路由.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
}
]
}
因此,在 LoginPageComponents 上,我只想导航到/products
路径(以防登录成功)
登录页面.component.ts
this.authService.logIn(this.credentials)
.then(_ => this.router.navigateByUrl('/products'))
.catch(this.handleLoginError.bind(this));
结果我什么也得不到。只是一个请求飞到服务器,我看到成功登录,仅此而已 - 没有错误等。
您能否提一些建议?
解决方案
您是否尝试过检查您收到的回复?
this.authService.logIn(this.credentials)
.then(res => {
console.log(res);
this.router.navigateByUrl('/products');
}).catch(this.handleLoginError.bind(this));
推荐阅读
- xml - 使用 XPath 更新 Android Manifest 中的 versionCode
- javascript - 我可以使用函数更改输入标签的最大属性吗?
- php - 为什么我的 sql select 语句在数据库中选择多行时返回空值?
- wpf - 如果我的 ObservableCollection 在构造时未初始化,为什么它不会在更改时更新 UI?
- python - 运行时保存 TensorFlow 状态(权重)
- facebook - 如何根据 created_date 从 Facebook Graph API 过滤潜在客户
- android - 如何从kotlin中的构造函数传递值获取数据
- python - 如何包装某些句子在从段落中提取它们之后标记,同时为最终输出保持相同的段落格式?
- c# - 来自与子查询的 C# LINQ 复合
- php - Wordpress 自定义 PHP 文件在访问时返回 404