Vue routing relative path jump method

Vue routing relative path jump method

Vue routing relative path jump

Today I encountered multi-layer routing when writing something. A relative path is required when jumping between routes. Therefore, I checked the official website and found that the append attribute and router.resolve method were used, so I listed the specific usage methods.

1. Append attribute

When the append attribute is set, the base path is added before the current (relative) path.

Type: boolean

Default value: false

  • For example, we navigate from /eth (base path) to a relative path /eth/block, /eth—>/eth/block, and the route is set to block
  • If the append attribute is added, the full path is /eth/block.
  • If not, the full path is /block

If the current route is /eth, jump to the child /eth/block

<router-link to="block" append> 
 /eth =====> /eth/block  
</router-link>

If the current route is /eth/login, jump to the same level /eth/block

<router-link to="../block" append>
 /eth/login =====> /eth/block 
</router-link>

If the current route is /eth/block, return to the previous level /eth

<router-link to="../" append>
 /eth/block =====> /eth 
</router-link>

2.router.resolve method

router.resolve(location, current?, append?)

Return value: route object

  • The resolved target location (same format as <router-link>'s to prop).
  • current is the current default route (usually you don't need to change it)
  • append allows you to append paths to the current route (similar to router-link)
export default {
  mounted() {
    //Get the route object to be redirected let routeObj = this.$router.resolve({
        path: '../'
      },
      this.$route,
      "append"
    );
    //Print and view the route object console.log(routeObj);
    //Route jump this.$router.push({
      path: routeObj.route.path,
      query: { //Pass parameter id in this way: this.id 
   }
    });
  }
}

Vue router dynamic routing click jump path address repeated append

Problems encountered when practicing writing vue router dynamic routing

When clicking multiple times, the address bar keeps adding duplicates.

insert image description here

After checking the code, I found that the relative path in the page was missing a '/' at the beginning; adding it will display normally.

as follows:

insert image description here

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Implementation of nested jump of vue routing view router-view
  • Solution for Vue routing this.route.push jump page not refreshing
  • Routing in Vue is not counted in history operations
  • Vue same route jump forced refresh the route component operation
  • Do you know what are the ways to jump routes in Vue?

<<:  Detailed explanation of the principles and usage of MySQL stored procedures

>>:  Steps to configure IIS10 under Win10 and support debugging ASP programs

Recommend

Design Theory: Hierarchy in Design

<br />Original text: http://andymao.com/andy...

Solution to the timeout problem when installing docker-compose with PIP

1: Installation command pip install docker-compos...

Pros and Cons of Vite and Vue CLI

There is a new build tool in the Vue ecosystem ca...

Vue realizes the function of book shopping cart

This article example shares the specific code of ...

React Hook usage examples (6 common hooks)

1. useState: Let functional components have state...

Solve the problem of inconsistent front and back end ports of Vue

Vue front and back end ports are inconsistent In ...

How to limit the number of records in a table in MySQL

Table of contents 1. Trigger Solution 2. Partitio...

Four ways to switch tab pages in VUE

Table of contents 1. Static implementation method...

How to use MySQL covering index and table return

Two major categories of indexes Storage engine us...

CSS performance optimization - detailed explanation of will-change usage

will-change tells the browser what changes will h...

The principle and direction of JavaScript this

How to determine what this points to? ①When calle...

React Synthetic Events Explained

Table of contents Start by clicking the input box...

How to quickly paginate MySQL data volumes of tens of millions

Preface In backend development, in order to preve...

mysql-8.0.16 winx64 latest installation tutorial with pictures and text

I just started learning about databases recently....

Detailed explanation of Xshell common problems and related configurations

This article introduces common problems of Xshell...