SoFunction
Updated on 2025-04-05

$ routing switching in Vue and how to pass parameters and get parameters

1. Two common ways to route

1) Declarative form:
	<router-link to="/login">
	<router-link :to="{ path: '/login' }">Home</router-link>
	<router-link :to="{ name: 'loginPage'}">User</router-link>
2) Programming:$(...)

The parameters of the method can be a string path, or an object describing the address.

	// If the existing route is (login in)	import LoginPage from "@/views/";
	const router = new VueRouter({
	  [{ path: "/login", name: "loginPage", component: LoginPage }]
	});
	
	// String (corresponding to the path above)	this.$('/login')
	
	// Object	this.$({path: '/login'});
	
	// The name of the route (corresponding to the name above)	this.$({ name: 'loginPage' })

2. Pass parameters and get parameters (query and params)

1) query method
this.$({&lt;!--{C}%3C!%2D%2D%20%2D%2D%3E--&gt;path:"/login",query:{&lt;!--{C}%3C!%2D%2D%20%2D%2D%3E--&gt;message:"Page jump successfully"}})

New page/routing Get parameters

(this.$);
2) Params method
this.$({&lt;!--{C}%3C!%2D%2D%20%2D%2D%3E--&gt;name:"loginPage",params:{&lt;!--{C}%3C!%2D%2D%20%2D%2D%3E--&gt;message:"Page jump successfully"}})

New page/routing Get parameters

(this.$);

Notice:this.$()In the methodpathCan't be withparamsUse together, otherwiseparamsWill be invalid. Need to usenameTo specify the page and configure it through routingnameAttribute access

The difference between the two methods is:
  • The parameters of the query parameter will be displayed in the address bar after the url.
  • Params passed parameters will not be displayed in the address bar (the parameters are invalid after refresh).

Summarize

This is the article about $() routing switching in Vue and how to transfer parameters and obtain parameters. For more related Vue $() routing switching content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!