0Pricing
Vue Academy · Lesson

Programmatic Navigation and useRouter

router.push(), router.replace(), router.go(), useRouter() and useRoute() composables.

Navigating From Code

Besides RouterLink, you often need to navigate from JavaScript — after a form submit or login. The useRouter composable gives you the router instance to do this.

Getting the Router

Call useRouter() inside <script setup>. The returned object exposes push, replace, go, and more.

import { useRouter } from 'vue-router'
const router = useRouter()

All lessons in this course

  1. Route Meta Fields and Typing
  2. Route Transitions and Animation
  3. Scroll Behavior Configuration
  4. Programmatic Navigation and useRouter
← Back to Vue Academy