Added simple router

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

22
package-lock.json generated
View File

@ -8,7 +8,8 @@
"name": "ca_vue_apps",
"version": "0.0.0",
"dependencies": {
"vue": "^3.3.4"
"vue": "^3.3.4",
"vue-router": "^4.2.5"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.2.3",
@ -471,6 +472,11 @@
"@vue/shared": "3.3.4"
}
},
"node_modules/@vue/devtools-api": {
"version": "6.5.0",
"resolved": "https://registry.npmjs.org/@vue/devtools-api/-/devtools-api-6.5.0.tgz",
"integrity": "sha512-o9KfBeaBmCKl10usN4crU53fYtC1r7jJwdGKjPT24t348rHxgfpZ0xL3Xm/gLUYnc0oTp8LAmrxOeLyu6tbk2Q=="
},
"node_modules/@vue/language-core": {
"version": "1.8.15",
"resolved": "https://registry.npmjs.org/@vue/language-core/-/language-core-1.8.15.tgz",
@ -864,6 +870,20 @@
"@vue/shared": "3.3.4"
}
},
"node_modules/vue-router": {
"version": "4.2.5",
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-4.2.5.tgz",
"integrity": "sha512-DIUpKcyg4+PTQKfFPX88UWhlagBEBEfJ5A8XDXRJLUnZOvcpMF8o/dnL90vpVkGaPbjvXazV/rC1qBKrZlFugw==",
"dependencies": {
"@vue/devtools-api": "^6.5.0"
},
"funding": {
"url": "https://github.com/sponsors/posva"
},
"peerDependencies": {
"vue": "^3.2.0"
}
},
"node_modules/vue-template-compiler": {
"version": "2.7.14",
"resolved": "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.7.14.tgz",

View File

@ -9,7 +9,8 @@
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.3.4"
"vue": "^3.3.4",
"vue-router": "^4.2.5"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.2.3",

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>