簡體   English   中英

Angular HTML5模式和ui-router返回403

[英]Angular HTML5 mode and ui-router returns 403

我正在使用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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM