Vue-router没有加载输入到浏览器的URL

时间:2017-01-10 20:13:33

标签: vue.js vue-router

我有一个使用Vue-router的Laravel 5.3项目。我在模板中使用<router-view></router-view>标签(home.blade.php)。

我遇到的唯一问题是我似乎无法通过在路由器中输入URL来获取视图。它仅在我的刀片文件中使用router-link时才有效。

这是我实现路由器的主要JS文件:

import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter);
Vue.use(require('vue-resource'));

Vue.http.headers.common['X-CSRF-TOKEN'] = $('meta[name="csrf-token"]').attr('content');

Vue.component(
    'passport-clients',
    require('./components/passport/Clients.vue')
);

Vue.component(
    'passport-authorized-clients',
    require('./components/passport/AuthorizedClients.vue')
);

Vue.component(
    'passport-personal-access-tokens',
    require('./components/passport/PersonalAccessTokens.vue')
);

const routes = [
  { path: '/view1', component: require('./components/view1.vue')},
  { path: '/view2', component: require('./components/view2.vue')},
  { path: '/view3', component: require('./components/view3.vue')}
]

const router = new VueRouter({
  routes: routes,
})

const app = new Vue({
  router
}).$mount('#app')

我的web.php文件:

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

//All the authentication routes
Auth::routes();

//Only routing needed for Laravel
Route::get('/{catchall?}', ['as' => 'start', 'middleware' => 'auth', function() {
    return view('home');
}])->where('catchall', '.*');

知道为什么会这样做吗?

1 个答案:

答案 0 :(得分:3)

您是否尝试在history: true内设置new VueRouter,如果您有后端,则不需要使用哈希网址。