解析器在到达确切 url 之前将我路由到第 404 页
Resolver route me to page 404 before reach the exact url
当我使用 url 'architecture/departements/3' 请求时,一切正常,方法 getListDepartement 被调用。但它首先将我路由到 404 未找到,然后将我路由到确切的 url
navigateToDepartement() {
this.router.navigate(['/reload']).then(() => {
this.router.navigate(['/architecture/departements/' + this.idBranche]);
})
}
这是解析器:
export class DepartmentResolveService implements Resolve<any[]>{
constructor(public brancheService: BrancheService) { }
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> {
return this.brancheService.getListDepartement(route.params['id'])
}
我的路由代码:
const routes: Routes = [
{
path: '',
children: [
{
path: '',
component: BranchesComponent,
},
{
path: 'departements/:id',
component: DepartmentListComponent,
resolve: { departement: DepartmentResolveService },
}
]
}
]
我想在到达 URL 之前阻止传递到 404。
我真的不明白你为什么调用 'reload' 页面你应该删除它,这是你应该做的:
navigateToDepartement() {
this.router.navigate(['/architecture/departements/' + this.idBranche]);
}
不需要调用重新加载页面,我认为它应该可以
当我使用 url 'architecture/departements/3' 请求时,一切正常,方法 getListDepartement 被调用。但它首先将我路由到 404 未找到,然后将我路由到确切的 url
navigateToDepartement() {
this.router.navigate(['/reload']).then(() => {
this.router.navigate(['/architecture/departements/' + this.idBranche]);
})
}
这是解析器:
export class DepartmentResolveService implements Resolve<any[]>{
constructor(public brancheService: BrancheService) { }
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> {
return this.brancheService.getListDepartement(route.params['id'])
}
我的路由代码:
const routes: Routes = [
{
path: '',
children: [
{
path: '',
component: BranchesComponent,
},
{
path: 'departements/:id',
component: DepartmentListComponent,
resolve: { departement: DepartmentResolveService },
}
]
}
]
我想在到达 URL 之前阻止传递到 404。
我真的不明白你为什么调用 'reload' 页面你应该删除它,这是你应该做的:
navigateToDepartement() {
this.router.navigate(['/architecture/departements/' + this.idBranche]);
}
不需要调用重新加载页面,我认为它应该可以