I had a project where the URL just worked fine when working locally by going to
localhost:9000/
the URL would become
http://localhost:9000/#/
As of some change I made it now goes to
http://localhost:9000/#!/ ( with an exclamation mark )
Also, other URLs become weird. if I try to click on a link that for example, goes to the dashboard. It doesn't take me there. Instead, it makes the URL like
/#!/#%2Fdashboard
and nothing happens after that. What did I do wrong and how can I possibly solve this? I can't show any code since I don't know where I went wrong. I followed the following tutorial and after that, the problem occurred. Perhaps the mistake is there?
tutorial link
I added my .config where I set up the routes.
.config(function ($routeProvider, $httpProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl',
controllerAs: 'vm',
activetab: 'main'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl',
controllerAs: 'vm',
activetab: 'about'
})
.when('/faq', {
templateUrl: 'views/faq.html',
controller: 'FaqCtrl',
controllerAs: 'vm',
activetab: 'faq'
})
.when('/dashboard', {
templateUrl: 'views/dashboard.html',
controller: 'DashboardCtrl',
controllerAs: 'vm',
activetab: 'dashboard'
})
.when('/logout', {
templateUrl: 'views/main.html',
controller: 'LogoutCtrl',
controllerAs: 'vm'
})
.otherwise({
redirectTo: '/'
});
$httpProvider.interceptors.push(['$q', '$window', '$localStorage', function($q, $window, $localStorage) {
return {
'request': function (config) {
config.headers = config.headers || {};
if ($localStorage.globals) {
config.headers.access_token = $localStorage.globals.currentUser.token;
}
return config;
},
'responseError': function(response) {
switch(response.status) {
case 403:
//$window.location = '/'
break;
case 404:
//$window.location = './404.html';
break;
case 500:
$window.location = './500.html';
break;
}
return $q.reject(response);
}
};
}]);
This is actually not a bug.
See commit-aa077e8
The default hash-prefix used for $location hash-bang URLs has changed from the empty string ('')
to the bang ('!')
.
If you actually want to have no hash-prefix, then you can restore the previous behavior by adding a configuration block to your application:
appModule.config(['$locationProvider', function($locationProvider) {
$locationProvider.hashPrefix('');
}]);
I have managed to solve this problem by using
$locationProvider.hashPrefix('');
It seems to be a bug in 1.6.0 angularjs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With