Added simple router

This commit is contained in:
2023-10-06 14:13:16 -05:00
parent 7e3058a4f1
commit c366605fe1
7 changed files with 83 additions and 3 deletions

View File

@@ -3,6 +3,19 @@ import HelloWorld from './components/HelloWorld.vue'
</script>
<template>
<div id="router">
<h1>Hello App!</h1>
<p>
<!-- use the router-link component for navigation. -->
<!-- specify the link by passing the `to` prop. -->
<!-- `<router-link>` will render an `<a>` tag with the correct `href` attribute -->
<router-link to="/">Go to Home</router-link>
<router-link to="/about">Go to About</router-link>
</p>
<!-- route outlet -->
<!-- component matched by the route will render here -->
<router-view></router-view>
</div>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" class="logo" alt="Vite logo" />
@@ -21,9 +34,11 @@ import HelloWorld from './components/HelloWorld.vue'
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vue:hover {
filter: drop-shadow(0 0 2em #42b883aa);
}

View File

@@ -1,5 +1,7 @@
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from "./router";
createApp(App).mount('#app')
createApp(App)
.use(router).mount('#app')

16
src/router/index.ts Normal file
View File

@@ -0,0 +1,16 @@
import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '../views/Home.vue'
import About from '../views/About.vue'
const routes = [
{ path: '/', component: Home },
{ path: '/about', component: About },
]
const router = createRouter({
// 4. Provide the history implementation to use. We are using the hash history for simplicity here.
history: createWebHashHistory(),
routes, // short for `routes: routes`
})
export default router;

13
src/views/About.vue Normal file
View File

@@ -0,0 +1,13 @@
<template lang="">
<div>
<h1>About</h1>
</div>
</template>
<script>
export default {
}
</script>
<style lang="">
</style>

13
src/views/Home.vue Normal file
View File

@@ -0,0 +1,13 @@
<template lang="">
<div>
<h1>Home</h1>
</div>
</template>
<script>
export default {
}
</script>
<style lang="">
</style>