laravel-Nginx上的历史记录模式的Vue路由器服务器配置不起作用

我从vue router documentation阅读了以下说明

Note: when using the history mode,the server needs to be properly configured so that a user directly visiting a deep link on your site
doesn’t get a 404.

所以,我尝试像下面这样配置我的nginx

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/laravel/public/;
    index index.php index.html index.htm;

    server_name working.dev;

    location /user {
        rewrite ^(.+)$/index.php last;

    }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php${
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

以下是我的Vue配置

var router = new VueRouter({
    hashbang: false,history: true,linkActiveClass: "active",root:  '/user'
});

但是,当用户直接访问我网站的深层链接时,我仍然收到404.

编辑:我也使用Laravel路由.以下是我的laravel路由.

Route::get('user',function() {
    return View::make('user.index');
});

最佳答案
我刚刚读了mattstauffer blog post,终于在Laravel路线中找到了解决方法.像下面

Route::get('user/{vue_capture?}',function() {
    return View::make('user.index');
})->where('vue_capture','[\/\w\.-]*');

当用户直接访问网站的深层链接时,它不会返回404.

dawei

【声明】:丽水站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。