VueJS 路由未定义
VueJS route is undefined
我正在尝试在 router-view
标签内呈现我的 vue 组件。但它给了我一个错误
TypeError: route is undefined
但我没有在任何地方使用 route
这个词。这是我的代码。
App.vue
<template>
<div id="app">
<my-header></my-header>
<router-view></router-view>
<my-footer></my-footer>
</div>
</template>
outerroutes.js
import welcome from './components/welcome.vue';
import insideSystem from './components/insideSystem.vue';
import forgotPassword from './components/forgotPassword.vue';
export const routes = [
{path:'',component:welcome},
{path:'/insideSystem',component:insideSystem},
{path:'/forgotPassword',component:forgotPassword}
];
main.js
import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import {routes} from './outerroutes';
Vue.use(VueRouter);
const router = new VueRouter({
routes,
mode:'history'
});
new Vue({
el: '#app',
routes,
render: h => h(App)
})
我想知道这个 route
来自哪里。
在outerroutes.js
中:
{path:'',component:welcome},
没有任何定义。尝试:
{path:'/',component:welcome},
此外,我不确定 main.js
中的 routes
是否需要花括号:
import {routes} from './outerroutes';
您正在创建一个路由器实例,如下所示;
const router = new VueRouter({
routes,
mode:'history'
});
但是你应该将 router
实例注入根 vue 实例中的 router 选项而不是 routes
new Vue({
el: '#app',
router,
//routes, not this
render: h => h(App)
})
我正在尝试在 router-view
标签内呈现我的 vue 组件。但它给了我一个错误
TypeError: route is undefined
但我没有在任何地方使用 route
这个词。这是我的代码。
App.vue
<template>
<div id="app">
<my-header></my-header>
<router-view></router-view>
<my-footer></my-footer>
</div>
</template>
outerroutes.js
import welcome from './components/welcome.vue';
import insideSystem from './components/insideSystem.vue';
import forgotPassword from './components/forgotPassword.vue';
export const routes = [
{path:'',component:welcome},
{path:'/insideSystem',component:insideSystem},
{path:'/forgotPassword',component:forgotPassword}
];
main.js
import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import {routes} from './outerroutes';
Vue.use(VueRouter);
const router = new VueRouter({
routes,
mode:'history'
});
new Vue({
el: '#app',
routes,
render: h => h(App)
})
我想知道这个 route
来自哪里。
在outerroutes.js
中:
{path:'',component:welcome},
没有任何定义。尝试:
{path:'/',component:welcome},
此外,我不确定 main.js
中的 routes
是否需要花括号:
import {routes} from './outerroutes';
您正在创建一个路由器实例,如下所示;
const router = new VueRouter({
routes,
mode:'history'
});
但是你应该将 router
实例注入根 vue 实例中的 router 选项而不是 routes
new Vue({
el: '#app',
router,
//routes, not this
render: h => h(App)
})