introduce
InstallInstallation Commands npm install vue-router --save If you use it in a modular project, you must explicitly install the routing function via import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) Modular use When we used the scaffolding import Vue from "vue"; import VueRouter from "vue-router"; import Home from "../views/Home.vue"; // 1. When we use other plug-ins, we must use Vue.use to install the plug-in Vue.use(VueRouter); // 2. Define routes, each route should map to a component const routes = [ { path: "/", name: "Home", component: Home, }, { path: "/about", name: "About", component: About }, ]; // 3. Create a router instance const router = new VueRouter({ //Configure the application relationship between routes and components routes, // (abbreviation) equivalent to routes: routes }); // 4. Export the router object, and then reference export default router in main.js; This file is specifically for configuring routing. Finally, after exporting import Vue from "vue"; import App from "./App.vue"; import router from "./router"; Vue.config.productionTip = false; new Vue({ router, // Add the router object to the vue instance, and you can use routing render: (h) => h(App), }).$mount("#app"); Our two component codes // About.vue <template> <div class="about"> <h1>About</h1> </div> </template> <script> export default { name: "About" } </script> <style scoped> </style> // Home.vue <template> <div class="home"> <h1>Home</h1> </div> </template> <script> export default { name: "Home", }; </script> <style scoped> </style> Finally, we write the following code in template> <div id="app"> <router-link to="/">Home</router-link> <router-link to="/about">About</router-link> <router-view></router-view> </div> </template> <style lang="scss"> </style> Use HTML5 history mode But when we start the program and access the page, This is because const router = new VueRouter({ mode: 'history', routes: [...] }) We just need to add Note: Therefore, you need to add a candidate resource on the server to cover all situations: if This is the end of this article about the installation and configuration of vue-route routing management. For more relevant vue route installation and configuration content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed example of MySQL (5.6 and below) parsing JSON
My system and software versions are as follows: S...
Table of contents View Disk Usage Disk Cleanup (D...
Moreover, an article website built with a blog pro...
Table of contents Preface 1. Recursive components...
1. Cause The official cerbot is too annoying. It ...
I. Introduction First, let me explain the version...
The execution relationship between the href jump ...
Copy code The code is as follows: 1. Sina Weibo &...
Table of contents background analyze Data simulat...
mysql-5.7.20-winx64.zipInstallation package witho...
Table of contents 1. Prototype chain inheritance ...
MySQL consistency log What happens to uncommitted...
The property names often heard in web design: con...
If MySQL version 5.0 already exists on the machin...
Flex Layout Flex is the abbreviation of Flexible ...