Vue Router 

NPM (Install)

// vue-cli 3.x 이상 
npm install vue-router@next
// vue-cli 2.x 
npm install vue-router --save 		// dependencies
or
npm install vue-router --save-dev 	// devDependencies
dependencies와 devDependencies의 차이는 다음과 같습니다.
"dependencies": 프로덕션 환경에서 응용 프로그램에 필요한 패키지.
"devDependencies": 로컬 개발 및 테스트에만 필요한 패키지.

main.js

  • vue-cli 3.x 이상
// main.js

import { createApp } from 'vue'
import App from './App.vue'
import router from './routes/index.js';

const app = createApp(App);

app.use(router);
app.mount('#app');
  • vue-cli 2.x 이상
// main.js

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

Vue.use(VueRouter)

routes/index.js

  • vue-cli 3.x 이상
// routes/index.js

import { createWebHistory, createRouter } from 'vue-router';

const routes = [
  {
    path: "/",
  },
 
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

export default router;

 

https://router.vuejs.org/installation.html#vue-cli

 

Installation | Vue Router

Installation Direct Download / CDN https://unpkg.com/vue-router/dist/vue-router.js (opens new window) Unpkg.com (opens new window) provides npm-based CDN links. The above link will always point to the latest release on npm. You can also use a specific vers

router.vuejs.org

 

반응형

+ Recent posts