为什么 Angular router.navigate 不导航?
Why Angular router.navigate not navigating?
我想导航子根,但在 1 次导航后 url 发生变化但组件未加载,但如果我刷新 url 组件正在加载。如果我在导航根目录中,url 更改但不加载,如果我不在导航根目录中,它正在加载。
链接..
http://localhost:4000/project-details/16/project-details
http://localhost:4000/project-details/21/project-details
//when select an option navigate to project-details/id
goToProjectDetails(projectId: any) {
this.router.navigate(['project-details', projectId]);
}
项目-details.component
ngOnInit() {
this.subscription = this.route.params.subscribe(() => {
this.getProject();
this.tableRender();
});
}
app.routers.ts
{
path: "project-details/:id",
children: [
{
path:'',
redirectTo: 'project-details',
pathMatch: 'full'
},
{ path: 'project-details', component: ProjectDetailsComponent },
{ path: 'translation', component: TranslationComponent },
{ path: 'env', component: EnvVariablesComponent },
{ path: 'urls', component: UrlsComponent },
]
,
component: ProjectDetailsMenuComponent,
data: {
id: "project.details",
}
...
我找到了解决方案:
//private state: StateService
ngOnInit() {
this.subscription = this.state.subscribeImmediately(() => {
this.getProject();
this.tableRender();
});
}
我想导航子根,但在 1 次导航后 url 发生变化但组件未加载,但如果我刷新 url 组件正在加载。如果我在导航根目录中,url 更改但不加载,如果我不在导航根目录中,它正在加载。
链接..
http://localhost:4000/project-details/16/project-details
http://localhost:4000/project-details/21/project-details
//when select an option navigate to project-details/id
goToProjectDetails(projectId: any) {
this.router.navigate(['project-details', projectId]);
}
项目-details.component
ngOnInit() {
this.subscription = this.route.params.subscribe(() => {
this.getProject();
this.tableRender();
});
}
app.routers.ts
{
path: "project-details/:id",
children: [
{
path:'',
redirectTo: 'project-details',
pathMatch: 'full'
},
{ path: 'project-details', component: ProjectDetailsComponent },
{ path: 'translation', component: TranslationComponent },
{ path: 'env', component: EnvVariablesComponent },
{ path: 'urls', component: UrlsComponent },
]
,
component: ProjectDetailsMenuComponent,
data: {
id: "project.details",
}
...
我找到了解决方案:
//private state: StateService
ngOnInit() {
this.subscription = this.state.subscribeImmediately(() => {
this.getProject();
this.tableRender();
});
}