This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Routing redirection renders an incorrect view at first load #10041
Closed
Description
Reproducted on angular 1.3.*, but not on 1.2.26.
Steps to reproduce, with this code (jsbin):
- Load the page
- You are redirected to /#/login -> OK
- ... but the displayed content comes from another view (called needsAuth) -> KO
- Reload
- The URI ends with /#/login -> OK
- The content comes from the login view -> OK
HTML Code:
<!DOCTYPE html>
<html ng-app='app'>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular-route.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div ng-view>
</div>
</body>
</html>
Javascript code
var template = '{{vm.text}}';
angular
.module('app', ['ngRoute'])
.config(['$routeProvider', routes])
.controller('needsAuthController', needsAuthController)
.controller('loginController', loginController)
.run(['$rootScope', '$location', registerRedirection]);
function routes($routeProvider){
$routeProvider
.when('/needsAuth', {
controller: 'needsAuthController',
controllerAs: 'vm',
template: template
})
.when('/login', {
controller: 'loginController',
controllerAs: 'vm',
template: template
})
.otherwise({
redirectTo: '/needsAuth'
});
}
function needsAuthController(){
var vm = this;
vm.text = 'needsAuth';
}
function loginController(){
var vm = this;
vm.text = 'login';
}
function registerRedirection($rootScope, $location){
$rootScope.$on('$routeChangeStart', function(event, next){
$location.path('/login');
});
}
Metadata
Metadata
Assignees
Labels
No labels