vue router

해적왕·2022년 12월 7일
0
post-custom-banner

index.js

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

const routes = [
  { path: '/', component: home, name: 'home' },
  {
    path: '/about', component: about, name: 'about',
    children: [
      { path: 'end', component: end, name: 'end' }
    ]
  },
]

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

export default router;

main.js

import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from "./router";

createApp(App).use(router).mount('#app')

app.vue

<template>
  <router-view />
</template>

<style scoped>
</style>

home.vue

<script setup>
</script>

<template>
  <router-link to="/about">
	 // 내용
  </router-link>
</template>
<script>
export default {
  name: "home",
  data: () => ({
  }),
};
</script>

about.vue

<template>
  <div
    <button @click="$router.push({ name: 'end' })">about</button>
    <router-view></router-view>
  </div>
</template>
<script>
export default {
  name: "about",
  data: () => ({}),
};
</script>

localhost:3000/about/end로 나옴

profile
프론트엔드
post-custom-banner

0개의 댓글