簡體   English   中英

Angular4-使用可選參數和查詢參數進行路由

[英]Angular4 - Routing with optional parameters and query parameters

在angular4路由中,我嘗試使用可選參數導航至特定路徑,但未導航至正確路徑,請參見以下代碼

我配置為的路線

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

我正在路由以下this.router.navigate(["login",{optionalParam:"param"}])登錄名,但是這正在導航至Register,我可以在路由器調試中觀察到URL重定向為“ login; optionalParam = param”以“注冊”。 可能是什么問題,我也面臨着queryParameters的相同問題。

我做了一個簡單的例子: 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM