Home > Article > Web Front-end > What is the difference between $router and $route in vue
router and route in Vue are two routing-related attributes, with different functions and meanings: 1. $router is an instance of Vue Router, which provides methods and attributes for navigation and routing management; 2. $route is the information object of the current active route, which contains information about the current route.
In Vue, router and route are two attributes related to routing, and their functions and meanings are different.
router is an instance of VueRouter, which provides some methods and properties to navigate and Manage routing. Through router, we can perform operations such as jumping to other routes, dynamic routing parameters, etc.
For example, you can use the $router.push() method to perform route jump:
// 在Vue组件中 methods: { goToAboutPage() { this.$router.push('/about'); } }
route is the information object of the current active route, which contains some relevant information of the current route, such as Paths, parameters, query parameters, etc. Through route, we can obtain current routing information or monitor routing changes.
For example, you can use $route.params to get the parameters of dynamic routing:
// 在Vue组件中 mounted() { console.log(this.$route.params.id); }
To summarize:
The above is the detailed content of What is the difference between $router and $route in vue. For more information, please follow other related articles on the PHP Chinese website!