


How to solve the problem that the routing page cannot be displayed properly when building in vue-router (detailed tutorial)
Below I will share with you an article that solves the problem that vue-router cannot display the routing page properly when building. It has a good reference value and I hope it will be helpful to everyone.
Create a webpack project using vue cli
Add vue-router and use routing to introduce a new component. At this time, the routing and links are written like this
const router = new VueRouter({ mode: 'history', base: __dirname, routes: [ { path: '/first', component: firstCom } ] })
<a href="/first" rel="external nofollow" >Try this!</a>
1. There is no problem with npm run dev
2. npm run build package
3. Start a service (for example: python -m SimpleHTTPServer) and then check the index.html page and find that the route will request the /first page.
4. Solution: Change the history in the routing configuration to hash, and change the /first in the link to /#/first. problem solved.
============Updated on 2017.8.24================
After searching for some information, I found that it is actually possible to use history for the router mode. The problem occurred when I was doing the jump. I took it for granted that I used window.location.href="", but actually I should use router.push. The handleSelect in the code is due to the use of a message processing method that appears in element ui. It can be understood that this method is triggered when the button is clicked. If the key of the button is 2, then jump to first, and if the key is 3, jump to second.
<script> export default { data () { return { } }, methods: { handleSelect(key, keyPath) { if (key == 2){ this.$router.push('first'); } else if (key == 3){ this.$router.push('second'); } } } } </script>
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
JavaScript Gypsophila navigation bar implementation method
computed, filter, get of vue.js , Detailed explanation of the usage and difference of set
##Detailed explanation of the whole process from buying a domain name to using pm2 to deploy the node.js project
The above is the detailed content of How to solve the problem that the routing page cannot be displayed properly when building in vue-router (detailed tutorial). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The vue-router error "NavigationDuplicated:Avoidedredundantnavigationtocurrentlocation" encountered in the Vue application – how to solve it? Vue.js is becoming more and more popular in front-end application development as a fast and flexible JavaScript framework. VueRouter is a code library of Vue.js used for routing management. However, sometimes

The latest news from this site on April 7 is that multiple bugs have been discovered in Microsoft Win1124H2Build26100, and it is temporarily not recommended to install it on commonly used devices. Windows 1124H2 is still in a very unstable stage. Although Microsoft will gradually fix the problem through monthly cumulative updates, it may take some time before this version is officially released and brings a stable experience to everyone. If any user has installed the 24H2 version image and encountered problems, it is recommended that the user reinstall it. It is now relatively stable. ZacBowden, encountered a Blue Screen of Death when trying to reset Windows 1124H2Build26100 version, and the "Reset this PC" function was supposed to fix system problems, but instead

Vue and Vue-Router: How to share data between components? Introduction: Vue is a popular JavaScript framework for building user interfaces. Vue-Router is Vue's official routing manager, used to implement single-page applications. In Vue applications, components are the basic units for building user interfaces. In many cases we need to share data between different components. This article will introduce some methods to help you achieve data sharing in Vue and Vue-Router, and

Microsoft released two more Windows 11 betas this week. Windows 11 Beta Build 22623.891 brings a search bar to Task Manager. Search bar in Task Manager Search bars were recently discovered in DevChannel, but users have to enable them manually. Users who publish on DevChannel and want to try out the feature can follow the instructions in Martin's article to learn how to use the ViveTool utility to get the search bar. This time, however, the search bar is official. Microsoft has enabled the feature in the Beta channel. The search box is located at the top of the Task Manager window and is permanent

Vue is a popular front-end framework that allows developers to quickly build efficient, reusable web applications. Vue-router is a plug-in in the Vue framework that helps developers easily manage application routing and navigation. However, when using Vue-router, you sometimes encounter a common error: "Error:Invalidroutecomponent:xxx". This article will explain the causes and solutions to this error. The reason lies in Vu

When using vue-router in a Vue application, the error message "Error: Avoidedredundantnavigationtocurrentlocation" sometimes appears. This error message means "avoiding redundant navigation to the current location" and is usually caused by clicking the same link repeatedly or using the same routing path. So, how to solve this problem? Use the exact modifier when defining the router

Using vue-router is a common way to implement routing control in Vue applications. However, when using vue-router, the error "Error: Failedtoresolveasynccomponent:xxx" sometimes occurs, which is caused by an asynchronous component loading error. In this article, we will explore this problem and provide solutions. Understand the principle of asynchronous component loading. In Vue, components can be created synchronously or asynchronously.

Vue-Router: How to use routing meta information to manage routes? Introduction: Vue-Router is the official routing manager of Vue.js, which can help us quickly build single-page applications (SPA). In addition to common routing functions, Vue-Router also supports the use of routing meta information to manage and control routing. Routing metainformation is a custom attribute that can be attached to a route, which can help us implement some special logic or permission control. 1. What is routing metainformation? The routing meta information is
