2017-06-21 176 views
1

main.js樣子:刪除Vue公司JS路由URL包括hashtag

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) 
}) 

我試着從URL中刪除#標籤... 進出口使用的WebPack的發展,正如你可以看到IM導入文件航線。 我看到這個錯誤,每次

"Uncaught TypeError: WEBPACK_IMPORTED_MODULE_1router__.a is not a constructor"

有誰有路由器的好醫生?

這是/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 
    } 
    ] 
}) 

回答

3

的VueRouter的import語句應該是

import VueRouter from 'vue-router' 

編輯

您在建立VueRouter ./router/index.js檔案itsels,所以加上mode:'history'物業本身

./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 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) 
}) 
+0

我已經改變它的main.js文件,現在有另一種不同的錯誤: - -Uncaught TypeError:routes.forEach不是函數 - – user3380738

+0

@ user3380738你能不能顯示你的''./route/index.js''文件 –

+0

作品完美!謝謝! @VamsiKrishna – user3380738