This time I will bring you an analysis of the vue mobile routing switching case. What are the precautions for vue mobile routing switching? The following is a practical case, let's take a look.
The most important of them are the following two problems:Switching of the browser navigation bar1. Switching the browser navigation bar
A page-> B page-> C pageIf I go from page A to page B and then to page C, there will be 3 historical recordsWe use an array to represent: ['/a', '/b', '/c']Then when I click the back button on the browser navigation bar, I will return to page B. At this time, I only need to determine whether page B exists. If it exists, it proves that I clicked the back button. . Then as long as I go back, I can click the browser's forward button. How to judge whether it is moving forward at this time? We can do this. When we go back to page B, doesn’t the history record still save the three paths ['/a', '/b', '/c']?We can delete page B The following path is now ['/a', '/b'];
If we go back to page A, then the path we save is ['/a']
But what if we enter some pages repeatedly.
A page-> B page-> C page-> B page-> C pageNow we take 5 steps and reach the second C page, then we take a step back and reach the B page
// 当没有key的时候会进入两次 beforeEach,我们只需保存带key的就行 const updateNavigations = (to) => { if (to.query[pathKey]) { store.commit('UPDATE_NAVIGATIONS', {path: to.fullPath}) } } router.beforeEach((to, from, next) => { let toIndex = store.state.navigations.findIndex(path => path === to.fullPath) if (toIndex >= 0) { // 存在该路径 let len = store.state.navigations.length-1 if (toIndex === len) { // 当前路径是最后一条,证明是同一个页面 console.log('refresh') } else { // 后退 store.commit('UPDATE_ROUTER_DIRECTION', { routerDirection: 'back' }) // 后退标志 store.commit('DELETE_NAVIGATION', { index: toIndex }) // 删除当前路径后面的路径 } }else{ // 不存在该路径 store.commit('UPDATE_ROUTER_DIRECTION', { routerDirection: 'forward' }) // 前进标志 updateNavigations(to) // 保存该连接 } const query = { ...to.query } // 存在就直接next, 防止死循环 if (!query['APP_KEY']) { // 不存在添加key ,再次 next query['APP_KEY'] = Math.random().toString(16).substring(2) next({ path: to.path, query}) }else{ next() } })
2. Sliding switching on IOS
A -> B -> CWhen we reach the C page and then slide to the left, finish sliding him Just enter the B page, but at this time it will still enter our beforeEach hook function and execute our above logic.
let touchEndTime = Date.now() window.addEventListener('touchend', () => { touchEndTime = Date.now() }) router.beforeEach((to, from, next) => { if ((Date.now() - touchEndTime) < 377) { // ios滑动切换 store.commit('UPDATE_ROUTER_DIRECTION', { routerDirection: '' }) } })
The above is also easy to understand, that is, we get the moment when the finger finally leaves the screen, and then compare it in beforeEach.
The difference between the last moment when the finger leaves the screen and our own transition in beforeEach Less than 337, even if it is the sliding switching of IOS
, that will solve the sliding switching problem of IOS.
But when IOS slides right to switch, it cannot monitor the moment when the finger leaves the screen (I don’t know what the ghost is), so IOS slides right to switch and cannot be judged as above.
I haven’t found a solution to this. For the time being, I can only solve the switch of left swiping back in IOS.
Basically, the two most troublesome points are the above two points. The rest can be set by listening to events, which is not difficult
Online DEMO Demonstration
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:
Detailed explanation of how to use jQuery class name selector (.class)
#
The above is the detailed content of Vue mobile terminal routing switching case analysis. For more information, please follow other related articles on the PHP Chinese website!

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.


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

Dreamweaver CS6
Visual web development tools

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

WebStorm Mac version
Useful JavaScript development tools

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

Atom editor mac version download
The most popular open source editor
