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
MediumPreserve 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>This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Routing and State
4Query State
Reading Query ValuesCommitting Search QueriesPreserving Other FiltersNormalizing Query NumbersRecap: Catalog Filters7Pinia Options Stores
Shared Store StateDerived Store GettersStore Actions and BoundsExtracting Reactive FieldsRecap: Seat Counter10Guarded Workflows
Store-Aware Access GuardsReturning After Sign-InNested Access PoliciesProtecting Unsaved DraftsRecap: Museum Pass2Navigation Actions
Navigation from HandlersReplacing HistoryHistory TravelCurrent Navigation LinksRecap: Save and Review5Nested Layouts
Parent and Child OutletsDefault Child ViewsRelative Child PathsAncestor Navigation StateRecap: Library Workspace8Store Design
Setup Store StructurePatching Related StateResetting Store StateComposing Related StoresRecap: Trip Pack11Workshop Planner Project
Planner RoutesShared Reservations