Programmatic Navigation | vue push query
Asidefromusing
Aside from using <router-link> to create anchor tags for declarative navigation, we can do this programmatically using the routers instance methods.
Navigate to a different location [1]Note: The examples below refer to the router instance as router. Inside a component, you can access the router using the $router property, e.g. this.$router.push(...). If youre using the Composition API, the router is accessible by calling useRouter()[2].
To navigate to a different URL, use router.push. This method pushes a new entry into the history stack, so when the user clicks the browser back button they will be taken to the previous URL.
This is the method called internally when you click a <router-link>, so clicking <router-link :to="..."> is the equivalent of calling router.push(...).
DeclarativeProgrammatic<router-link :to="...">router.push(...)The argument can be a string path, or a location descriptor object. Examples:
js// literal string ...