【问题标题】:Vue-router not working properlyVue路由器无法正常工作
【发布时间】:2018-04-14 18:03:42
【问题描述】:

我已经安装了带有节点的 vue-router。 这是我的项目地址http://localhost/UserApp/public

我使用的两条 vue 路由是/home & /about 所以当我点击主路线时。它会将我重定向到http://localhost/home 但它应该是http://localhost/UserApp/public/home。 所以当我重新加载页面时。它抛出object not found 错误。因为没有http://localhost/home 这样的路由。 我该如何解决这个问题?

app.js

import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [
  { path: '/home', component: Home },
  { path: '/about', component: About }
]

const router = new VueRouter({
   mode : 'history',
   routes // short for `routes: routes`
})

web.php

Route::get('/{name}',function(){
    return redirect('/');
})->where('name','[A-Za-z]+');

Myheader.vue

<router-link to="/home" class="navbar-item">Home</router-link>
<router-link to="/about" class="navbar-item">About</router-link>

【问题讨论】:

    标签: php laravel laravel-5 vue-router


    【解决方案1】:

    你需要在vue-router的配置中更改基础应用路径,

    文档:https://router.vuejs.org/en/api/options.html#base

    base据我所知应该是/UserApp/public

    作为路由选项,请尝试:

    Route::get('/{any}', function(){
        return view('index');
    })->where('any', '.*');
    

    【讨论】:

      猜你喜欢
      • 2020-05-28
      • 2019-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-09
      • 2019-12-31
      • 2016-11-26
      • 2014-12-05
      相关资源
      最近更新 更多