角度网址正在添加不需要的字符 [英] angular url is adding unwanted characters
问题描述
我有一个项目,通过转到
I had a project where the URL just worked fine when working locally by going to
本地主机:9000/
网址会变成
由于我所做的一些更改,现在转到
As of some change I made it now goes to
http://localhost:9000/#!/(带感叹号)>
http://localhost:9000/#!/ ( with an exclamation mark )
此外,其他 URL 变得奇怪.如果我尝试点击一个链接,例如,转到仪表板.它不带我去那里.相反,它使 URL 像
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
/#!/#%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?
我在设置路由的地方添加了我的 .config.
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);
}
};
}]);
推荐答案
这实际上不是错误.
用于 $location hash-bang URL 的默认哈希前缀已从空字符串 ('')
更改为 bang ('!')
.
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('');
}]);
这篇关于角度网址正在添加不需要的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!