add router

This commit is contained in:
Tim Wundenberg
2021-07-28 18:24:14 +02:00
parent 06d31c558d
commit 21d61f60bf
7 changed files with 80 additions and 20 deletions

View File

@@ -1924,6 +1924,11 @@
} }
} }
}, },
"@vue/devtools-api": {
"version": "6.0.0-beta.15",
"resolved": "https://registry.nlark.com/@vue/devtools-api/download/@vue/devtools-api-6.0.0-beta.15.tgz",
"integrity": "sha1-rXyzhOBi8WW8+cg3MhJb/7wq2D0="
},
"@vue/preload-webpack-plugin": { "@vue/preload-webpack-plugin": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.nlark.com/@vue/preload-webpack-plugin/download/@vue/preload-webpack-plugin-1.1.2.tgz", "resolved": "https://registry.nlark.com/@vue/preload-webpack-plugin/download/@vue/preload-webpack-plugin-1.1.2.tgz",
@@ -11331,9 +11336,12 @@
} }
}, },
"vue-router": { "vue-router": {
"version": "3.5.2", "version": "4.0.10",
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.5.2.tgz", "resolved": "https://registry.nlark.com/vue-router/download/vue-router-4.0.10.tgz",
"integrity": "sha512-807gn82hTnjCYGrnF3eNmIw/dk7/GE4B5h69BlyCK9KHASwSloD1Sjcn06zg9fVG4fYH2DrsNBZkpLtb25WtaQ==" "integrity": "sha1-7I/aAylJsqMdMnMXD483bobrUqw=",
"requires": {
"@vue/devtools-api": "^6.0.0-beta.14"
}
}, },
"vue-style-loader": { "vue-style-loader": {
"version": "4.1.3", "version": "4.1.3",

View File

@@ -10,11 +10,12 @@
"dependencies": { "dependencies": {
"core-js": "^3.6.5", "core-js": "^3.6.5",
"vue": "^3.0.0", "vue": "^3.0.0",
"vue-router": "^3.5.2" "vue-router": "^4.0.0-0"
}, },
"devDependencies": { "devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0", "@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0", "@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "^4.5.13",
"@vue/cli-service": "~4.5.0", "@vue/cli-service": "~4.5.0",
"@vue/compiler-sfc": "^3.0.0", "@vue/compiler-sfc": "^3.0.0",
"babel-eslint": "^10.1.0", "babel-eslint": "^10.1.0",

View File

@@ -1,21 +1,11 @@
<template> <template>
<div> <div id="nav">
<img alt="Vue logo" src="./assets/logo.png" /> <router-link to="/">Home</router-link> |
<HelloWorld msg="Welcome to Your Vue.js App" /> <router-link to="/about">About</router-link>
<router-view />
</div> </div>
</template> </template>
<script>
import HelloWorld from "./components/HelloWorld.vue";
export default {
name: "App",
components: {
HelloWorld,
},
};
</script>
<style> <style>
#app { #app {
font-family: Avenir, Helvetica, Arial, sans-serif; font-family: Avenir, Helvetica, Arial, sans-serif;
@@ -23,6 +13,18 @@ export default {
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
text-align: center; text-align: center;
color: #2c3e50; color: #2c3e50;
margin-top: 60px; }
#nav {
padding: 30px;
}
#nav a {
font-weight: bold;
color: #2c3e50;
}
#nav a.router-link-exact-active {
color: #42b983;
} }
</style> </style>

View File

@@ -1,4 +1,5 @@
import { createApp } from 'vue' import { createApp } from 'vue'
import App from './App.vue' import App from './App.vue'
import router from './router'
createApp(App).mount('#app') createApp(App).use(router).mount('#app')

View File

@@ -0,0 +1,25 @@
import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
}
]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
export default router

View File

@@ -0,0 +1,5 @@
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>

View File

@@ -0,0 +1,18 @@
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</template>
<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'
export default {
name: 'Home',
components: {
HelloWorld
}
}
</script>