In Angular, What is 'pathmatch: full' and what effect does it have?

前端 未结 4 1320
小鲜肉
小鲜肉 2020-11-30 02:49

In here it is use pathmatch as full and when i delete this pathmatch it doesn\'t even load the app or run the project

import { NgModule } from \'@angular/cor         


        
4条回答
  •  青春惊慌失措
    2020-11-30 03:33

    RouterModule.forRoot([
          { path: 'welcome', component: WelcomeComponent },
          { path: '', redirectTo: 'welcome', pathMatch: 'full' },
          { path: '**', component: 'pageNotFoundComponent' }
        ])
    

    Case 1 pathMatch:'full': In this case, when app is launched on localhost:4200 (or some server) the default page will be welcome screen, since the url will be https://localhost:4200/

    If https://localhost:4200/gibberish this will redirect to pageNotFound screen because of path:'**' wildcard

    Case 2 pathMatch:'prefix':

    If the routes have { path: '', redirectTo: 'welcome', pathMatch: 'prefix' }, now this will never reach the wildcard route since every url would match path:'' defined.

提交回复
热议问题