Angular4 - 使用可选参数和查询参数进行路由

时间:2017-07-28 10:13:14

标签: angular angular4-router

在angular4路由中,我尝试导航到具有可选参数的特定路径,但它没有导航到正确的路径,请参阅下面的代码

我配置为

的路线
{ path:"login",component:"LoginComponent"},
 {path:"register",component:"RegisterComponent"},
 {path:"**",redirectTo:"register"}

我正在路由登录,如下所示 this.router.navigate(["login",{optionalParam:"param"}])但这是导航到Register,我可以在路由器调试中观察到url从“login; optionalParam = param”重定向到“register”。可能是什么问题,我也面临与queryParameters相同的问题。

1 个答案:

答案 0 :(得分:-1)

我做了一个简单的例子:https://plnkr.co/edit/F3mfg9jXHZEAyZz6xZjf

使用重定向和查询。

let routes: Routes = [
    { path: '', component: MainComponent },
    { path: 'login',component: LoginComponent},
    { path: 'redirection',component: RedirectComponent},
    { path: '**',redirectTo: 'redirection'}
];

<a [routerLink]="['/login',{'plop':'pom'}]">go to login with query</a>
相关问题