加入收藏 | 设为首页 | 会员中心 | 我要投稿 商洛站长网 (https://www.0914zz.com/)- AI应用、CDN、边缘计算、云计算、物联网!
当前位置: 首页 > 运营中心 > Nginx > 正文

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

发布时间:2021-01-12 03:22:50 所属栏目:Nginx 来源:互联网
导读:我从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

我从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.

(编辑:商洛站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读