๊ด€๋ฆฌ ๋ฉ”๋‰ด

๐Ÿ–ฅ dev-ruby

[Vue] #14 - router ๋ณธ๋ฌธ

Vue

[Vue] #14 - router

ruby_s 2021. 8. 6. 11:20
728x90
๋ฐ˜์‘ํ˜•
SMALL

1. router ์„ค์น˜ํ•˜๊ธฐ

npm install vue-router@4

2. router ํด๋” ์ƒ์„ฑ

src/router.js ์ƒ์„ฑ ํ›„

import { createWebHistory, createRouter } from "vue-router"; // import ์ปดํฌ๋„ŒํŠธ const routes = [ { path : "/list", // ์ด ๊ฒฝ๋กœ๋กœ ์ ‘์†ํ•˜๋ฉด component : List, // ์ด ์ปดํฌ๋„ŒํŠธ๋กœ ๋„˜์–ด๊ฐ€๊ฒŒ ํ•ด์ฃผ์„ธ์š” }, { path : "/home", component : Home, }, { path : "/detail/:id", //detail/:์•„๋ฌด๋ฌธ์ž component : Detail, }, ]; const router = createRouter({ history: createWebHistory(), routes, }); export default router;

์ด๋Ÿฐ ํ˜•์‹์œผ๋กœ ์ž‘์„ฑ

3. router ์‚ฌ์šฉํ•˜๊ธฐ

<router-view> <router-link>

ex

<router-link to="/list">๋ฆฌ์ŠคํŠธํŽ˜์ด์ง€</router-link> ๋ฆฌ์ŠคํŠธํŽ˜์ด์ง€ ๋ผ๋Š” ๊ธ€์ž๋ฅผ ๋ˆ„๋ฅด๋ฉด /listํŽ˜์ด์ง€๋กœ ๋„˜์–ด๊ฐ„๋‹ค <router-view :blog="bloglist"></router-view> ํ•˜๋ฉด props ์ „๋‹ฌ ๊ฐ€๋Šฅ

 

728x90
๋ฐ˜์‘ํ˜•
LIST