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
1. Download the MySQL 5.7.11 zip installation pac...
Steps to configure whitelist access in mysql 1. L...
Effect: The title has its own serial number, the ...
Table of contents Add Configuration json configur...
Table of contents Preface The role of deconstruct...
What are HTTP Headers HTTP is an abbreviation of ...
Mysql sets boolean type 1. Tinyint type We create...
This article shares the specific code of jQuery t...
Preface I once encountered a difficult problem. I...
Notice! ! ! This situation can actually be avoide...
This article introduces the sample code of CSS to...
I knew before that to synchronously obtain the re...
MySQL 5.7.21 winx64 free installation version con...
Before I start, let me emphasize that process.env...
I have been learning porters recently. I feel lik...