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

Laravel + Vue.js 应用程序路由无法正常工作。 当我运行 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 地址而不是域名,它工作正常。

标签: laravel vue.js


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2018-01-17
    • 2017-10-15
    • 2016-12-05
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 2019-04-21
    相关资源
    最近更新 更多