$vueaddrouterWARNThereareuncommitedchangesinthecurrentrepository,it's recommended to commit or stash them first.? Still proceed? Yes📦 Installing @vue/cli-plugin-router...+ @vue/cli-plugin-router@4.4.1added 2 packages from 1 contributor, updated 1 package and audited 1283 packages in 5.023s46 packages are looking for funding run `npm fund` for detailsfound 0 vulnerabilities✔ Successfully installed plugin: @vue/cli-plugin-router? Use history mode for router? (Requires proper server setup for index fallback in production) Yes🚀 Invoking generator for @vue/cli-plugin-router...⚓ Running completion hooks...✔ Successfully invoked generator for plugin: @vue/cli-plugin-router
가능한 project 생성하자 마자 add 하기!
이런 메시지 뜨지 않게 해라~
ex)
App.vue
<template> <divid="app"> <divid="nav"><!-- 이렇게 a tag 쓰면 page reload 됨 --> <ahref="/">Home</a> <ahref="/about">About</a> <br><!-- 그래서 router-link 를 써야 함! page reload 되면 우리가 vue를 쓸 이유가 없음! --> <router-linkto="/">Home</router-link> | <router-linkto="/about">About</router-link> </div> <router-view/> </div></template>
router > index.js
router 안에 있는 index.js 는 Django 에서 urls.py 같은 것!
import Vue from'vue'import VueRouter from'vue-router'import Home from'../views/Home.vue'import About from'../views/About.vue'Vue.use(VueRouter)// Django 에서 urls.py 같은 것!constroutes= [ { path:'/', name:'Home', component: Home }, { path:'/about', name:'About', component: About }]constrouter=newVueRouter({ mode:'history', base:process.env.BASE_URL, routes})exportdefault router
views/ directory
URL(/) 과 mapping 될 component들이 들어가는 directory
URL을 하사 받을 애들~!
views/ 에 있는 Component들은, router/index.js 로 가서 import 한다!