Routes如下【AppRoutingModule】:
const routes: Routes = [
  {
    path:'',
    component: HomeComponent
  },
  {
    path: 'product',
    component: ProductComponent
  }
];

插座【app.component.html】:
<router-outlet></router-outlet>

 

RouterLink
<a [routerLink]="['/']">主页</a>
<a [routerLink]="['/product']">商品详情</a>
Router:
<button type="button" value="商品详情" (click)="toProductDetails()">商品详情</button>
export class AppComponent {
  title = 'app';
  constructor(private router: Router) {

  }
  toProductDetails() {
    this.router.navigate(['/product']);
  }
}

页面不存在

const routes: Routes = [
  {
    path:'',
    component: HomeComponent
  },
  {
    path: 'product',
    component: ProductComponent
  }
  ,
  {
    path: '**',
    component: Code404Component  //放最后,不然先匹配这个
  }
];

<p>
页面不存在
</p>

 

posted on 2018-04-21 18:23  chester·chen  阅读(118)  评论(0编辑  收藏  举报