Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of Angular 1 otherwise route in Angular 2

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}
])
like image 981
ssougnez Avatar asked Dec 20 '15 13:12

ssougnez


People also ask

What would you use in angular 2 to define route?

We use the router-outlet directive, an Angular 2 Routing directive that displays the active route (like ng-view ).

What are the types of routes in Angular?

Angular Router supports multiple outlets in the same application. A component has one associated primary route and can have auxiliary routes. Auxiliary routes enable developers to navigate multiple routes at the same time.

Can we use 2 router outlet in Angular?

You can have multiple router-outlet in same template by configuring your router and providing name to your router-outlet, you can achieve this as follows. Advantage of below approach is thats you can avoid dirty looking URL with it. eg: /home(aux:login) etc.


1 Answers

This hasn't currently been implemented in angular 2. The best current solution is to use a solution like @Gary showed.

{ path: '**', component: PageNotFoundComponent }

as shown in the angular guide routing section(https://angular.io/docs/ts/latest/guide/router.html).

like image 109
aheigins Avatar answered Oct 14 '22 03:10

aheigins