我的main.js
看起来像:
import Vue from 'vue'
import VueRouter from './router'
import routes from './router/index.js'
Vue.use(VueRouter)
const router = new VueRouter({
routes,
mode: 'history'
})
new Vue({
el: '#app',
router,
render: h => h(App)
})
我试图从网址中删除主题标签... 我使用Webpack进行开发,你可以看到我导入路由文件。 我每次都看到这个错误
“未捕获的TypeError:WEBPACK_IMPORTED_MODULE_1router __。a不是 构造函数“
有没有人有路由器的好文档?
这是/router/index.js文件
import Vue from 'vue'
import VueRouter from 'vue-router'
import Settings from '@/components/Settings'
import Login from '@/components/Login'
Vue.use(VueRouter)
export default new VueRouter({
routes: [{
path: '/',
name: 'Login',
component: Login
},
{
path: '/Settings',
name: 'Settings',
component: Settings
}
]
})
答案 0 :(得分:3)
VueRouter的import语句应为
import VueRouter from 'vue-router'
修改强>
您正在./router/index.js
文件中设置VueRouter,因此请在其中添加mode:'history'
属性
<强> ./路由器/ index.js 强>
import Vue from 'vue'
import VueRouter from 'vue-router'
import Settings from '@/components/Settings'
import Login from '@/components/Login'
Vue.use(VueRouter)
export const router = new VueRouter({
mode: 'history',
routes: [{
path: '/',
name: 'Login',
component: Login
},
{
path: '/Settings',
name: 'Settings',
component: Settings
}
]
})
<强> main.js 强>
import Vue from 'vue'
import {router} from './router/index.js'
new Vue({
el: '#app',
router,
render: h => h(App)
})