[英]Configure IIS URL Rewrite module for AngularJS HTML5Mode Still Not Working
[英]IIS URL rewrite module with angularJS does not work
我有一個單頁webapp,其中任何以請求開頭的請求,例如http://localhost/appname/request*
,主頁都使用IIS URL重寫模塊發送回客戶端。
Angular收到網頁后,便會看到路線。 我需要確保Angular拾取了routeParams。
客戶端請求: http://localhost/appname/request/param1/param2
$routeProvider.when('/request/:param1/:param2',{
templateUrl : 'app/views/myView.html',
controller : 'MyCtrl',
caseInsensitiveMatch : true
});
$routeProvider.otherwise({ redirectTo: '/' , caseInsensitiveMatch : true });
$locationProvider.html5Mode(true).hashPrefix('!');
控制器監聽$routeChangeSuccess
。
app.controller('MyCtrl',function($scope){
$scope.$on('$routeChangeSuccess',function(event,routeData,$timeout,$rootScope){
//routeData.pathParams are blank
});
});
URL也更改為主頁。 即我被重定向到http://localhost/appname
。
我做錯了什么?
如果我理解正確,則想獲取路由參數,但是正確的方法是將$ routeParams注入控制器:
app.controller('MyCtrl',function($scope, $routeParams){
if($routeParams.param1){
alert('SUPER FLY!');
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.