我在Homestead中运行了Laravel 5.2安装程序,并使用Vue.js路由器构建了SPA。我正在尝试从我知道可以完成的URL中完全删除#hash,但是我不断收到错误消息:
我已经rewrite ^(.+)$ /index.html last;
在Homestead中添加了我的vhosts文件:
server {
listen 80;
listen 443 ssl;
server_name app.myproject.dev;
root "/home/vagrant/Code/vibecast/app.myproject.com/public";
rewrite ^(.+)$ /index.html last;
index index.html index.htm index.php;
charset utf-8;
...
}
当我重新启动并打开页面时,出现一个500 Internal Server Error
。
我需要在Laravel中添加路线吗?
var router = new VueRouter({
hashbang: false,
history: true,
linkActiveClass: "active"
})
在浏览时,我可以在没有#hash(或修改后的hosts文件)的情况下正常工作,但是在重新加载页面时失败。
我已经通过Matt Stauffer的演示应用程序设法找到了解决方案。首先,无需更新vhosts文件。只需将SPA / Vue.js路由更新routes.php
为:
Route::get('/{vue?}', 'AppController@spa')->where('vue', '[\/\w\.-]*');
如果您有管理面板,并且不想考虑其前缀
Route::get('/{vue?}', 'AppController@spa')->where('vue','^(?!panel).*$');
当然,像这样初始化Vue.js路由器:
const router = new VueRouter({
history: true,
hashbang: false,
linkActiveClass: 'active'
})
router.mode = 'html5'
参考:https : //github.com/mattstauffer/suggestive/blob/master/app/Http/routes.php#L9
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句