【发布时间】:2021-08-12 07:56:34
【问题描述】:
我希望能够根据 URL 路由更改页面上的数据,即 test/1 获取我的数据集 1,test/2 获取我的数据集 2。但是,如果我已经在 test/1 上并尝试要使用路由器导航导航到 test/2(反之亦然),它会更改 url 但仅此而已,不会触发其他任何内容。
我的路线有以下定义:
const routes: Routes = [
{
path: 'test',
children: [
{
path: ':id',
component: TestComponent
},
{ path: '**', redirectTo: '', pathMatch: 'full' }
]
},
];
TS 组件:
value: any;
constructor(private router: Router, private, private route: ActivatedRoute) {
this.value = this.route.snapshot.params.id;
}
goToPage(value: any) {
this.router.navigate(['/test', value]);
}
我的 html 组件:
{{value}}
<button (click)="goToPage(1)">One</button>
<button (click)="goToPage(2)">Two</button>
我也尝试将 { onSameUrlNavigation: 'reload' } 添加到 RouterModule.forRoot,但仍然没有做任何事情。
注意: 问题不在于获取参数,问题在于必须刷新页面才能触发与新参数关联的所有进程。
【问题讨论】:
标签: angular