角度路由参数

时间:2017-12-04 12:03:48

标签: html angular typescript routing

我想知道,即使我路由/去到另一个页面,路由所拥有的参数是否会保留?< / p>

例如:

localhost:4200/welcomepage?param=true =&gt; localhost:4200/secondpage?param=true

2 个答案:

答案 0 :(得分:0)

是的,你可以这样试试,

import { ModuleWithProviders }  from '@angular/core';
import { CanActivate, Routes, RouterModule } from '@angular/router';

/* Component */
import { welcomepage } from '../../modules/welcomepage/welcomepage.component';

const appRoutes: Routes = [
  {
    path: 'welcomepage/:param',
    component: welcomepage
  }
];

export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

And in HTML page

<a [routerLink]="['/welcomepage', 'true']">Welcome</a>

并在HTML页面中

答案 1 :(得分:0)

导航到其他页面时,请尝试按以下步骤传递现有参数

constructor(private route: ActivatedRoute,
private router: Router) { }

const queryParams = Object.assign({}, this.route.snapshot.queryParams);
this.router.navigate(['./secondpage'], { queryParams: queryParams});