[英]Angular html5 mode not redirecting
我將AngularJs與Ruby on Rails一起使用。
我在angular中將html5選項設置為true: $locationProvider.html5Mode(true)
但是現在當我嘗試瀏覽應用程序中的頁面時,它只會更改瀏覽器URL欄中的URL。 但是除非重新加載頁面,否則頁面本身不會改變。 只有這樣,它才能轉到指定的頁面。
這是我的Angular路由的樣子:
@test.config(['$routeProvider', '$locationProvider', ($routeProvider, $locationProvider) ->
# Route for '/'
$routeProvider.when('/', { templateUrl: '../../views/visitors/index.html.erb', controller: 'VisitorsCtrl' } )
$routeProvider.when('/users', { templateUrl: '../../views/users/index.html.erb', controller: 'UsersCtrl' } )
# Default
$routeProvider.otherwise( { redirectTo: "/" } )
$locationProvider.html5Mode(true)
])
在根頁面上,我有一個元素: <h2><a ng-click="viewUsers()">Users</a></h2>
在這里調用viewUsers()
:
@test.controller 'VisitorsCtrl', ['$scope', '$location', '$http', ($scope, $location, $http) ->
$scope.viewUsers = ->
$location.path('/users')
console.log("Redirected")
]
要使這種路由生效,還需要什么呢?
新的角度路線:
Test.config ($routeProvider, $locationProvider) ->
$routeProvider
.when '/',
templateUrl: '../../views/visitors/index.html.erb',
controller: 'VisitorsCtrl'
.when '/users',
templateUrl: '../../views/users/index.html.erb',
controller: 'UsersCtrl'
嘗試改為使用以下內容:
$window.location.href = '/users'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.