Vue Router


Vue Router


ルータのインストール

$ npm i vue-router@4

ルータ接続

  • use接続ルータ
  • // main.js
    
    import { createApp } from 'vue'
    import App from './App'
    import router from './routes/index.js'
    
    
    createApp(App)
      .use(router)
      .mount('body')
  • createRouterexport
  • ルータの構成
    |使用
  • createWebHashHistory適用Hashモード
  • // ./routes/index.js
    
    import { createRouter, createWebHashHistory } from 'vue-router'
    import Home from './Home'
    import About from './About'
    
    export default createRouter({
      // Hash, History(서버 셋팅 필요)
      history: createWebHashHistory(), // Hash 모드
      // pages
      routes: [
        {
          path: '/',
          component: Home
        },
        {
          path: '/about',
          component: About
        }
      ]
    })