Menu
CoddyTech

Navigation from Handlers

Part of the Routing and State section of Coddy's Vue journey. Lesson 6 of 55.

A script handler can navigate after doing application work. Call useRouter() during setup, then use router.push when the action is ready. In this example, blank input keeps the current page; a valid draft opens the named summary route.

const router = useRouter();
function continueToSummary() {
  if (!draft.value.trim()) return;
  router.push({ name: 'summary' });
}

Do not call useRouter for the first time inside a later button event. Setup obtains the injected instance, and the handler reuses it. A push adds a navigation entry, so a later Back action can revisit the preceding location.

challenge icon

Challenge

Medium

Complete proceed() in the shell. Read the bound input#name; an empty or whitespace-only name keeps the app at /. Otherwise button#proceed navigates to the named details route at /details using router.push. The shell keeps the entered name.

Keep the supplied route readout and bootstrap files.

Try it yourself

<!doctype html><html><head><meta charset="UTF-8"><title>Routing practice</title></head><body><div id="app"></div><script type="module" src="./main.js"></script></body></html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Routing and State