系统相关
首页 > 系统相关> > laravel-Nginx上的历史记录模式的Vue路由器服务器配置不起作用

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.

标签:vue-router,laravel-routing,laravel,nginx,vue-js
来源: https://codeday.me/bug/20191118/2031277.html