试图理解重定向路由示例
Trying to understand redirect route example
来自文档
https://angular.io/guide/router
带“**”的路线有什么作用?两个星号对应什么?
const appRoutes: Routes = [
{ path: 'crisis-center', component: CrisisListComponent },
{ path: 'heroes', component: HeroListComponent },
{ path: '', redirectTo: '/heroes', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent }
];
快速浏览一下文档,我认为这是一个通配符路由。
引自文档:
'Leave the default and the wildcard routes! These are concerns at the top level of the application itself.'
'各路由模块按导入顺序扩充路由配置...
匹配每个 URL 的通配符路由将拦截导航到英雄路由的尝试。'
这是一个wildcard route。上面没有匹配的任何 URL 的包罗万象。
您不必拥有其中之一,但如果您没有,当用户导航到错误的路线时,he/she 将不会看到 404。他们会看到一个空白页面,即只是令人困惑。
这让我们有机会向他们传达信息——更好的用户体验!
来自文档 https://angular.io/guide/router
带“**”的路线有什么作用?两个星号对应什么?
const appRoutes: Routes = [
{ path: 'crisis-center', component: CrisisListComponent },
{ path: 'heroes', component: HeroListComponent },
{ path: '', redirectTo: '/heroes', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent }
];
快速浏览一下文档,我认为这是一个通配符路由。
引自文档: 'Leave the default and the wildcard routes! These are concerns at the top level of the application itself.'
'各路由模块按导入顺序扩充路由配置... 匹配每个 URL 的通配符路由将拦截导航到英雄路由的尝试。'
这是一个wildcard route。上面没有匹配的任何 URL 的包罗万象。
您不必拥有其中之一,但如果您没有,当用户导航到错误的路线时,he/she 将不会看到 404。他们会看到一个空白页面,即只是令人困惑。
这让我们有机会向他们传达信息——更好的用户体验!