router-outlet
をDashboardComponent
の中に作成しようとしています。router-outler
は、app.component.html
に存在します。プライマリルータのコンセント経由で提供されるコンポーネントの内部に角型ルータのコンセントを使用するにはどうすればよいですか?
私が達成しようとしている流れはこのように書きます:ユーザーがログインした後
は、ユーザーが
DashboardComponent
をロードします/dashboard
にリダイレクトされます。mat-sidenav
でクリックしたリンクに応じてAComponent
、BComponent
、CComponent
-DashboardComponent
はmat-sidenav-container
mat-sidenav
とのリンクやdiv
コンテナ、私はさまざまなコンポーネントを提供する必要があり、その内部が含まれています。ある
、パスlocalhost:4200/dashboard/componentA
はそうでDashboardComponent
さんのdivコンテナ内AComponent
とを示すべきです。
- パス
/dashboard
は私がrouter-outlet
を使用してDashboardComponent
内部の部品を表示する方法を把握しようと苦労しています/dashboard/componentA
にリダイレクトする必要があります。
これは可能ですか?これを行うための良い方法はありますか?
の作業コード:https://stackblitz.com/edit/angular-qvacwn/
app.routing.ts
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { AComponent } from './a/a.component';
import { BComponent } from './b/b.component';
import { CComponent } from './c/c.component';
export const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'dashboard', component: DashboardComponent, outlet: 'dashboard',
children: [
{ path: '', component: AComponent },
{ path: 'componentA', component: AComponent },
{ path: 'componentB', component: BComponent },
{ path: 'componentC', component: CComponent }
]},
// otherwise redirect to home
// { path: '**', redirectTo: '' }
];
これは問題を解決しますが、作業コードの編集URLを共有してください。コード – devN
が表示され、回答が1つしか回答としてマークできないことがわかりました。 oops – devN
https://stackblitz.com/edit/angular-jhr51r?file=app%2Fapp.routing.ts – Gautam