【问题标题】:Angular 2 RC5 and above - How to show an error page when no route matches?Angular 2 RC5 及更高版本 - 当没有路由匹配时如何显示错误页面?
【发布时间】:2016-12-30 22:42:35
【问题描述】:

我当前的 Route 配置如下所示

{
    path: '',
    redirectTo: 'register/account',
    pathMatch: 'full'
},
{
    path: 'register/account',
    component: AccountRegisterComponent
},
 {
    path: 'register/auto/:Id',
    component:AutoregisterComponent
},

如果用户尝试导航到“/register/auto”。目前我在控制台中看到一个空白页和一个错误。 如何显示 404 错误或提示此页面在全球范围内不可用的消息?

【问题讨论】:

    标签: javascript angular typescript error-handling routing


    【解决方案1】:

    angular2 cheatsheet 你可以这样做:

    {path: '**', redirectTo: '/404' }
    

    例如,您可能会遇到这样的情况:

    {path: '/404', component: NotFoundComponent},
    {path: '**', redirectTo: '/404' }
    

    希望有帮助

    【讨论】:

      猜你喜欢
      • 2017-01-02
      • 2018-11-16
      • 2016-12-22
      • 2017-01-21
      • 2018-01-05
      • 2021-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多