This time I will bring you Routinginterface exception when vue-router is built, and solve the problem of routing interface exception when vue-router is builtNotesThere are Which ones, the following are practical cases, let’s take a look.
Use vue cli to create a webpack project
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>Try this!</a>
1. There is no problem with npm run dev
2. npm run build packaging
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.
============2017.8.24Update================
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 because element is used A message processing method that appears in 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>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How to deal with the white screen on the homepage after vue build is packaged
How Native uses fetch to implement the image upload function
The above is the detailed content of Routing interface exception when vue-router is built. For more information, please follow other related articles on the PHP Chinese website!

Vue应用中遇到vue-router的错误“NavigationDuplicated:Avoidedredundantnavigationtocurrentlocation”–怎么解决?Vue.js作为快速而灵活的JavaScript框架在前端应用开发中越来越受欢迎。VueRouter是Vue.js的一个代码库,用于进行路由管理。然而,有时

在Vue应用中使用vue-router时,有时候会出现“Error:Avoidedredundantnavigationtocurrentlocation”的错误信息。这个错误信息的意思是“避免了到当前位置的冗余导航”,通常是因为重复点击了同一个链接或者使用了相同的路由路径导致的。那么,怎么解决这个问题呢?使用exact修饰符在定义router

Vue-Router:如何使用路由元信息来管理路由?简介:Vue-Router是Vue.js官方的路由管理器,它可以帮助我们快速构建单页应用程序(SPA)。除了常见的路由功能外,Vue-Router还支持使用路由元信息来管理和控制路由。路由元信息是可以附加到路由上的自定义属性,它可以帮助我们实现一些特殊的逻辑或者权限控制。一、什么是路由元信息?路由元信息是

在Vue应用中使用vue-router是一种常见的方式来实现路由控制。然而,在使用vue-router的时候,有时候会出现“Error:Failedtoresolveasynccomponent:xxx”的错误,这是由于异步组件加载错误导致的。在本文中,我们将探讨这个问题,并提供解决方案。理解异步组件加载原理在Vue中,组件可以被同步或异步地创建

Vue是一个流行的前端框架,它允许开发者快速构建高效、可重用的web应用程序。Vue-router是Vue框架中的一个插件,可以帮助开发者轻松管理应用的路由和导航。但是,在使用Vue-router的过程中,有时候会遇到一个常见的错误:“Error:Invalidroutecomponent:xxx”。这篇文章将介绍这个错误的原因和解决方法。原因在Vu

Vue和Vue-Router:如何在组件之间共享数据?简介:Vue是一个流行的JavaScript框架,用于构建用户界面。Vue-Router是Vue的官方路由管理器,用于实现单页面应用。在Vue应用中,组件是构建用户界面的基本单位。在许多情况下,我们需要在不同的组件之间共享数据。本文将介绍一些方法,帮助你在Vue和Vue-Router中实现数据共享,以及

最近我尝试在Vue应用中使用vue-router,但遇到了一个问题:“UncaughtTypeError:Cannotreadproperty'push'ofundefined”。这个问题的原因是什么,以及如何解决呢?首先,让我们了解一下vue-router。vue-router是Vue.js官方的路由管理插件,可以帮助我们构建单页应用(SPA


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver Mac version
Visual web development tools