Angular 1 的等价物,否则在 Angular 2 中路由 [英] Equivalent of Angular 1 otherwise route in Angular 2
问题描述
我正在为我的应用程序使用 Angular 2 路由,它运行良好,但我不知道如何定义否则"路由.因此,如果当前 URL 与任何支持的"路由不对应,则将显示一个路由.
I'm using Angular 2 routing for my application and it works pretty well but I have no idea how to define the "otherwise" route. So a route that will be displayed if none if the current URL does not correspond to any "supported" route.
以下是我当前配置的示例:
Here is an example of my current configuration:
@RouteConfig([
{ path: '/', name: 'Home', component: StoryComponent, useAsDefault: true },
{ path: '/story', name: 'Story', component: StoryComponent },
{ path: '/subscription', name: 'Subscription', component: SubscriptionComponent}
])
推荐答案
这目前还没有在 angular 2 中实现.目前最好的解决方案是使用像 @Gary 所示的解决方案.
This hasn't currently been implemented in angular 2. The best current solution is to use a solution like @Gary showed.
{ 路径:'**',组件:PageNotFoundComponent }
如angular guide路由部分所示(https://angular.io/docs/ts/latest/guide/router.html).
as shown in the angular guide routing section(https://angular.io/docs/ts/latest/guide/router.html).
这篇关于Angular 1 的等价物,否则在 Angular 2 中路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!