What are nested routes and why are they useful?
hierarchical UI-to-URL mapping.
nested routes render children inside a parent's router-view, preserving shared layouts while URL segments swap nested content.
flat routes with duplicated parent wrappers in every child.
What's really being asked
This question probes whether you understand that modern single-page app routers mirror URL structure to component hierarchy. It checks if you know how to use nested route configurations and nested router-view outlets to build persistent layouts without repeating code. The interviewer wants to see that you think in terms of component trees driven by URL segments rather than treating every page as an isolated top-level view.
The full answer
Four things in order. First, a definition: nested routes are child route objects declared under a parent route's children array that render inside a nested router-view outlet in the parent component. Second, the why: they keep parent shell components such as navigation sidebars, tabs, or context headers mounted and persistent while only the child region swaps, preserving local state and avoiding layout duplication. Third, the mechanism: the parent component template contains its own router-view below its persistent UI, and the router matches the remaining URL segment against the children array to decide which component to inject. Fourth, a concrete scenario: a user dashboard where /user/:id is the parent route rendering a User shell with a nested router-view, and /user/:id/profile and /user/:id/posts are child routes that render UserProfile and UserPosts inside that outlet.
The mistakes people make
Treating every route as a top-level path and copying the parent layout into each child component. This breaks DRY and destroys parent-level state when navigating between siblings. Another red flag is claiming nested routes require deeply nested URLs; candidates should know that a child path starting with / is treated as a root path, so you can nest components without nesting the URL. Finally, forgetting that visiting the parent path without a child match leaves the nested router-view empty unless you provide an empty path child.
What usually comes next
How do you handle a default child view when the parent route matches? How do named routes interact with nested children? What happens to parent route guards or data fetching when only the child segment changes? How would you implement breadcrumbs or deep-linking tabs with nested routes?
A concrete example
Imagine a SaaS admin panel. The route /admin has a parent Admin component with a sidebar and a main content area containing a router-view. Nested children include /admin/users rendering a UserList, /admin/users/:id rendering a UserDetail, and /admin/settings rendering SettingsPanel. Navigating between users and settings keeps the sidebar mounted and its scroll position intact, while only the main content area updates. If you visit /admin alone, an empty path child renders a dashboard overview so the outlet is never blank.
Interview question
In a nested route setup where /admin/users and /admin/settings are children of /admin, what happens to the Admin parent component when a user navigates between the two child pages?
- a.It remains mounted and only the content inside its nested router-view is swapped.Correct
- b.It unmounts and remounts, requiring the router to restore the sidebar scroll position automatically.
- c.It re-runs all parent-level route guards because the matched URL segments changed.
- d.It is replaced by the child component in the root router-view unless the child path starts with a forward slash.
Why? this is the answer
Nested routes are designed to keep parent shell components mounted while only the child region inside the nested router-view updates, preserving local state and layout. Option B is wrong because the parent does not unmount—scroll position is maintained precisely because the component persists across child navigations.
Just read this? Test yourself on what you have been reading.
Read the original → router.vuejs.org
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on vue — each one lists the topics its interview covers.
See open roles