Skip to content

Instantly share code, notes, and snippets.

@nikoloza
Last active March 16, 2016 23:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikoloza/4ab3a94a3c6511bb1dac to your computer and use it in GitHub Desktop.
Save nikoloza/4ab3a94a3c6511bb1dac to your computer and use it in GitHub Desktop.
Angular ui-router redirectTo trick
// define app
angular.module('app', [])
// listen to state changes
.config(function($rootScope) {
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState) {
// redirectTo
if (toState.redirectTo) {
event.preventDefault();
$state.go(toState.redirectTo, toParams);
}
});
})
// states
.config(function($stateProvider) {
$stateProvider
.state('home', {
url: '',
redirectTo: 'home.list'
})
.state('home.list', {
url: '/list'
});
});
@nikoloza
Copy link
Author

It's kind of a hack that makes routes redirecting to child states by default. No need to do url: '', it still does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment