Menu
CoddyTech

Returning After Sign-In

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

A sign-in redirect can carry the intended destination so the workflow continues afterward. Preserve the full path when query state matters, then replace the sign-in history entry with the accepted destination after the local session changes.

return {name:'sign-in',query:{returnUrl:to.fullPath}};
// After the local sign-in action:
router.replace(acceptedReturnUrl);

Treat a return value as input, not automatically trusted navigation. Accept only the internal location shape your app supports and use a safe fallback for missing or invalid values. Avoid sending the person straight back to sign-in. A real application also needs server authorization independent of these client navigation checks.

challenge icon

Challenge

Medium

Preserve the intended destination during a sign-in redirect. Put to.fullPath in Login query returnUrl. After local sign-in, replace Login with that target if it is a string starting with one slash, not two, and is not exactly /login; otherwise use /desk. Keep query values such as tab=plans. The app handles only local navigation, and no external redirect is permitted by this contract.

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