0
啓用$locationProvider.html5Mode(true);
和<base href="/" />
後index.html
路由在手動重新加載後開始崩潰。
尋找解決方案我發現.htaccess
規則將解決這個問題,但不同的配置沒有幫助。
也許這是因爲我的index.html
是在子目錄/views/index.html
.htaccess
:
Options +FollowSymLinks
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L] # /views/index.html doesn't work as well
</ifModule>
route config
app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {
templateUrl: 'home.html',
controller: 'AddTaskCtrl',
controllerAs: 'AddTask'
})
.when('/chat', { //this route breaks on manual refresh
templateUrl: 'chat.html',
controller: 'ChatCtrl',
controllerAs: 'chat'
})
}]);
儘管問題在'.htaccess'文件不是,你鏈接到FAQ非常有幫助。謝謝 – lomboboo