How to use `otherwise` in ui-router of angular 2?

angular, angular-ui-router, angularjs, javascript

Solution

The `UIRouterModule.forRoot` docs show an example of how to use the `otherwise` property:

UIRouterModule.forRoot({ states: [loginState], otherwise: '/index' }),
UIRouterModule.forChild({ states: [homeState] })

Problem

In ui-router we can add `otherwise` to handle invalid/unregistered state. Here's in AngularJS ``` $urlRouterProvider.otherwise('/index'); ``` Meaning, that every invalid URL will go to `'/index'` eventually. How do we do the same thing in ui-router for Angular 2? I've already used `UIRouterModule.forRoot()` and `UIRouterModule.forChild()` in `imports` of `app.module.ts`. ``` UIRouterModule.forRoot({ states: [loginState] }), UIRouterModule.forChild({ states: [homeState] }) ```

Original source