我从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'
});
编辑:我也使用Laravel路由.以下是我的laravel路由.
Route::get('user',function() {
return View::make('user.index');
});
最佳答案
我刚刚读了mattstauffer blog post,终于在Laravel路线中找到了解决方法.像下面
原文链接:https://www.f2er.com/nginx/532301.htmlRoute::get('user/{vue_capture?}',function() {
return View::make('user.index');
})->where('vue_capture','[\/\w\.-]*');