我希望能够根据 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' }
]
},
];
Run Code Online (Sandbox Code Playgroud)
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]);
}
Run Code Online (Sandbox Code Playgroud)
我的 html 组件:
{{value}}
<button (click)="goToPage(1)">One</button>
<button (click)="goToPage(2)">Two</button>
Run Code Online (Sandbox Code Playgroud)
我还尝试将 { onSameUrlNavigation: 'reload' } 添加到 RouterModule.forRoot,但仍然没有执行任何操作。
注意:问题不在于获取参数,问题在于必须刷新页面才能触发与新参数关联的所有进程。
angular ×1