0
我構建了一個小型的網絡應用程序,我使用UI-Router來瀏覽它的頁面。除了瀏覽器刷新或使用狀態鏈接訪問特定頁面之外,一切正常。我嘗試了幾個解決方案發布在同一主題上,但其中沒有一個可能是由於缺少額外信息。如何重新加載瀏覽器並在AngularJS UI-Router中保持當前狀態?
當我點擊下面的ui-sref鏈接時,我會看到'mysite/content'並且頁面顯示正常,但是一旦我刷新它或者嘗試通過粘貼鏈接來訪問它時,就不會找到頁面。
能否請你幫我,使其正常工作。提前致謝。
HTML
<p ui-sref="content">Link To Content</p>
AngularJS
var app = angular.module('myApp',['ui.router']);
app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function($stateProvider, $urlRouteProvider, $locationProvider){
$urlRouteProvider.otherwise('/');
$stateProvider
.state('home', {
url: '/',
views: {
'': { templateUrl: '/app/templates/wrapper.html'},
'[email protected]': { templateUrl: '/app/templates/nav.html'},
'[email protected]': { templateUrl: '/app/templates/header.html'},
'[email protected]': { templateUrl: '/app/templates/footer.html'}
}
})
.state('content', {
url: '/content',
views: {
'': { templateUrl: '/app/templates/content.html'},
'[email protected]': { templateUrl: '/app/templates/nav.html'},
'[email protected]': { templateUrl: '/app/templates/header.html'},
'[email protected]': { templateUrl: '/app/templates/footer.html'}
}
});
$locationProvider.html5Mode(true);
}])
你有需要可以將任何數據加載頁面之前得到解決?也許你的應用程序數據沒有加載... –
目前該應用程序是完全空的。現在我注意到,如果將$ locationProvider.html5Mode(true)設置爲false,它將按預期工作,但鏈接中會顯示破折號。試圖解決它 –