路由使用
- app-routing.module.ts 中配置路由
import {
FunComponent } from './components/fun/fun.component'
import {
HomeComponent } from './components/home/home.component'
import {
Son1Component } from './components/son1/son1.component'
import {
Son2Component } from './components/son2/son2.component'
const routes: Routes = [
{
path: '', redirectTo: 'home', pathMatch: 'full' },
{
path: 'home', component: HomeComponent, children: [
{
path: '', redirectTo: 'son1', pathMatch: 'full' },
{
path: 'son1', component: Son1Component },
{
path: 'son2', component: Son2Component },
],
},
{
path: 'fun/:id', component: FunComponent },
]
<h2>
<a routerLink="/home" routerLinkActive="active">home</a>
<a routerLink="/fun" routerLinkActive="active">fun</a>
</h2>
<router-outlet></router-outlet>
<h3>
<a routerLinkActive="active" routerLink=