13

Angular 4 でのルーティングに助けが必要です。このように URL を表示したいと思います。最初のユーザーの詳細を表示をクリックした場合、Localhost:4200/user/1。これを行う方法について少し混乱しています。以下のコードで最善を尽くしましたが、まだ機能しません。

app-routing.module.ts

    const appRoutes: Routes = [
        { path: '', redirectTo: '/dashboard', pathMatch: 'full' },
        { path: 'dashboard', component: DashboardComponent },
        { path: 'user', component: UserComponent, children: [
            
            { path: 'create-new-user', component: CreateNewUserComponent },
            { path: 'user-list', component: UserListComponent },
            { path: 'user-detail/:id', component: UserDetailComponent },

    ]},
    ];
    
    
    @NgModule({
        imports: [RouterModule.forRoot(appRoutes)],
        exports: [RouterModule]
    })
    export class AppRoutingModule {
    
    }
4

4 に答える 4