Laravel + Vue.js 应用程序路由无法正常工作

Posted

技术标签:

【中文标题】Laravel + Vue.js 应用程序路由无法正常工作【英文标题】:Laravel + Vue.js application routing not working properly 【发布时间】:2019-04-16 10:21:50 【问题描述】:

。 当我运行 laravel + vuejs 应用程序“http://127.0.0.1:8000/user”时,一切正常,但是当我使用此 url “http://localhost/Ecommerce/”在 xampp 服务器上运行我的应用程序时,vue-router 无法正常工作。 例如,当我单击导航链接“用户”时,它将重定向到 "http://localhost/user" 而不是 "http://localhost/Ecommerce/user" 。 请帮忙。

【问题讨论】:

请告诉我们你在 Laravel 和 vue-router 中的路由是什么。 web.php Route::get('/', function () return view('welcome'); );授权::路由(); Route::get('/home', 'HomeController@index')->name('home'); Route::get('path',"HomeController@index")->where('path', '([A-z\d-\/_.]+)?'); 和 app.js 是 require('./bootstrap'); window.Vue = require('vue');从 'vue-router' 导入 VueRouter Vue.use(VueRouter) const routes = [ path: '/dashboard', component:require('./components/Dashboard.vue') , path: '/user',组件:require('./components/User.vue') ] Vue.component('example-component', require('./components/ExampleComponent.vue')); const router = new VueRouter( mode: 'history', routes // 缩写 routes: routes ) const app = new Vue( el: '#app', router ); 感谢@Delena Malan 的回复 如果我使用 IP 地址而不是域名,它工作正常。 【参考方案1】:

尝试在创建 VueRouter 时添加 base url,例如

new VueRouter(
    base: '/Ecommerce/', 
    routes: [...],
);

【讨论】:

以上是关于Laravel + Vue.js 应用程序路由无法正常工作的主要内容,如果未能解决你的问题,请参考以下文章

在 Vue JS 组件中使用 Laravel 路由的最佳方法是啥

来自 Vue.js 的 Laravel API 调用导致 GET 路由的 CORS

无法为 api 路由 laravel 设置 cookie

无法在 Laravel/Vue.Js 中执行 Ajax 请求

子域 Laravel 路由和 Vue.js

Vue.js 组件中的 Laravel 路由链接?