我使用的是ui-router
和HTML模式。
但如果我重新加载页面或使用绝对URL,我会得到403。
这是我的Nginx重写:
location / {
try_files $uri $uri/ /index.html;
}
我添加了.htaccess
:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
</ifModule>
但它仍然不起作用。我的路线:
.config(["$locationProvider", function ($locationProvider) {
$locationProvider.html5Mode(true);
}])
.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/app/dashboard');
.state('app.dashboard', {
url: '/dashboard',
templateUrl: '/app/dashboard/dashboard.html',
})
.state('app.categories', {
url: '/categories',
templateUrl: '/app/category/category.html',
resolve: {
loadJs: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('/app/category/category.app.js');
}]
}
})
我已经在index.html
上设置了<base href="/">
如果我在仪表板中并重新加载它,它会返回403 Forbidden
我错过了什么?。
像这样更改您的第一个location
块:
location / {
index index.html;
# This is done because Angular doesn't perform a page refresh when using
# HTML5 mode, so all page refresh requests done, the sever render the 'index.html' file
try_files $uri /index.html;
}