2017-02-11 12 views
0

マイリンク角度2 [routerLink]ナビゲートが、URL

<a [routerLink]="['/login']"> 
     <i class="glyphicon glyphicon-user"></i> Login 
    </a> 

マイルート

const routes: Routes = [ 
    { path: 'login', component: LoginComponent }, 
    { path: 'register', component: UserRegisterComponent }, 
    { path: 'auctions', component: AuctionListComponent }, 
    { path: 'auction/:id', canActivate: [ AuctionDetailGuard ], component: AuctionDetailComponent }, 
    { path: 'supplier/:id', component: SupplierDetailComponent } 
]; 

オークション、オークション/に移動しrouterlinks更新しません:idとサプライヤーを/:IDをログインと登録はできませんが、どちらかをクリックすると正しいコンポーネントに移動しますが、URLはlocalhost:xxxx/loginに変わり、localhost:xxxx/previousUrlに戻ります。

<a routerLink="/login"> 
    <i class="glyphicon glyphicon-user"></i> Login 
</a> 
+1

ブラウザのコンソールにエラーが出るのですか? –

+0

'LoginComponent'や' UserRegisterComponent'のどこにでも 'router.navigateXxx(...)'がありますか? –

+0

はい、何とか私のログインフォームにエラーがありました。 –

答えて

0

として働く他のrouterlink、です。 これは、あなたがそれを使用する方法です:

const routes: Routes = [ 
    { path: 'login', component: LoginComponent }, 
    { path: 'register', component: UserRegisterComponent }, 
    { path: 'auctions', component: AuctionListComponent, children: [ 
    { path: ':id', canActivate: [ AuctionDetailGuard ], component: AuctionDetailComponent }, 
    { path: ':id/edit', component: AuctionDetailEditComponent } 
    ]}, 

    { path: 'supplier/:id', component: SupplierDetailComponent } 
]; 

// This is what you can place on the item 
<a [routerLink]="[idOfItem]">Link to Item</a> 

// And this method you call in your component.ts file 
// Add relativeTo to make it relative to the current route 
// so you'll add the "edit" after the called ID. 
this.router.navigate(['edit'], { relativeTo: this.route }); 
+1

全く同じ結果が得られたので、何も変わりませんでした。 –

+0

login.tsコードを共有してください。 – Aravind