我有我的路由設置如下圖所示如何路由到子鏈接?
app.routing.ts
import { Routes, RouterModule } from "@angular/router";
import { Test1Component } from "./pages/test1/test1.component";
import { Test2Component } from "./pages/test2/test2.component";
import { AuthService } from './shared/auth.service';
import { LoginComponent } from './login/login.component';
import { HomeComponent } from './home/home.component';
const APP_ROUTES: Routes = [
{
path: "login",
component: LoginComponent
},{
path: "home",
component: HomeComponent,
children: [{
path: "test1",
component: Test1Component,
outlet: "contentarea"
},{
path: "test2",
component: Test2Component,
outlet: "contentarea"
}]
}];
export const routing = RouterModule.forRoot(APP_ROUTES);
app.component.html
<router-outlet></router-outlet>
home.component.html
<div class="row">
<div class="col-xs-12">
<h1>Home</h1>
<a [routerLink]="['/home/test1']">Go to Test 1</a> <!-- Not working -->
<router-outlet name="contentarea"></router-outlet>
</div>
</div>
我能夠路由到http://localhost:4200/home
和http://localhost:4200/login
,但是當我嘗試導航到http://localhost:4200/test1
時失敗。
如何修復鏈接,以便當我去http://localhost:4200/home/test1
它加載test1
在contentarea
?
我想這可以通過'[routerLink] =「['/ home',{outlet:{contentarea:'test1'}}]」'' –
@PankajParkar我可以做到這一點,但創建帶圓括號的醜陋網址 –
因爲這是'router-outlet'打算如何工作IMO。你不能像分段路線那樣在路線中提到他們.. –