angular路由path:' ',与path:'**'的区别

有一个路由配置如下:

const routes: Routes = [
  {
    path:'home',
    component:HomeComponent
  },
  {
    path:'news',
    component:NewsComponent
  },
  {
    path:'',
    redirectTo:'home',
    pathMatch: 'full'//pathMatch:prefix和full,prefix表示以path开头,如path:'a' 实际访问的路径为'a/b',就可以匹配到
                     //full:path完全匹配
  },
  {
    path:'**',//上面匹配不上的路径,都匹配到这
    redirectTo:'home'
  }
];

路由地址为:

1 "localhost:4200/home",匹配到Home组件

2 "localhost:4200/news",匹配到News组件

3 "localhost:4200/",匹配到Home组件

4 "localhost:4200/user",由于没有配置user对应的组件,则匹配到**,最后转发到"localhost:4200/home",显示为Home组件

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章