How to do default load a default child route in angular 1.5 using ui-router

77 Views Asked by At

Hi I want to load a default child route as soon as i load the page Please check the code :

$stateProvider.state('userlist', {
    url: '/users',
    component: 'users',
    data:{"name":"abhi"},
    resolve: {
      users: function(UserService) {
        return UserService.list();
      }
    }
  });
  $stateProvider.state('userlist.detail', {
    url: '/:userId',
    component: 'userDetail',
    resolve: {
      user: function($transition$, users) {
        return users.find(user => user.id == $transition$.params().userId);
      }
    }
  });
  $stateProvider.state('userlist.id', {
    url: '/:username',
    component: 'userName',
    resolve: {
      user: function($transition$, users) {
        return users.find(user => user.name == $transition$.params().username);
      }
    }
  });
});

by default route is navigating to /users . I want it to navigate to /user/userId by default .

1

There are 1 best solutions below

0
On

By using otherwise you can set default route

Remember: your child state already has params, and you can't load them with otherwise for this you have to change state with $state.go() in your controller

app.config(function($urlRouterProvider){
     $urlRouterProvider.otherwise('/index');
})

more information