[英]AngularJS otherwise function redirects me to wrong route
我有類似這樣的路線:
$routeProvider
.when('/settings', { templateUrl: 'settingsTemplateURL', controller: settingsCtrl })
.when('/profile', { templateUrl: 'profileTemplateURL', controller: profileCtrl })
.otherwise({ redirectTo: '/settings' });
我在這樣的地址上使用我的webb:localhost / testapp /#/ settings或localhost / testapp /#/ profile等...
當我請求地址時,問題就開始了:localhost / testapp在此刻,否則功能會將我重定向到localhost / testapp#/ settings上,其中'testapp'之后的斜杠丟失了。 這是AngularJS版本之間的差異,因為此問題是在將AngularJS從1.0.7版本更新到1.2.13之后出現的
有人可以幫我嗎? 謝謝大衛
問題是localhost
。 嘗試使用: http://127.0.0.1/
: http://127.0.0.1/
而不是localhost
另外,當$ .route嘗試恢復模板時,您仍然可能會遇到問題,有時由於無法發送正確的標頭而無法正常工作,但這取決於您的設置。
奏效了嗎?
要使其在本地主機中工作,您必須像這樣遠程調用路由:
$routeProvider.when('/home', {
templateUrl: 'http://yoururl.com/model/app/whatever.php',
controller: 'Dashboard'
})
確保添加受信任的來源:
$sceDelegateProvider.resourceUrlWhitelist(['self','http://yoururl.com/model/app/**']);
和你的PHP:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: origin, content-type, accept');
而且有效。
這是它可以與localhost
一起使用的唯一方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.