Last active
March 16, 2016 23:27
-
-
Save nikoloza/4ab3a94a3c6511bb1dac to your computer and use it in GitHub Desktop.
Angular ui-router redirectTo trick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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' | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.