Question presented to candidate: "We are adding pages to a Vue 3 single-page app. Walk me through setting up Vue Router from scratch: where routes are defined, how links and the page outlet work, and which history mode you would pick for production."
What a strong answer should cover:
createRouter({ history, routes })plusapp.use(router); each route record maps apath(and ideally aname) to a component.<RouterView />is the outlet that renders the matched component;<RouterLink>renders a real<a>that navigates without a page reload and getsrouter-link-active/router-link-exact-activeclasses.- The three histories:
createWebHistory(clean URLs, needs a server fallback toindex.html),createWebHashHistory(#/about, no server config, worse for SEO),createMemoryHistory(SSR and tests). - Lazy-loaded route components with
() => import(...)so each page is its own chunk, and a catch-all/:pathMatch(.*)*route for 404s. - Current versions: Vue Router 5 is a drop-in upgrade from 4 for code-based routes; file-based routing moved into the core package.
Clarifying questions expected:
- "Where is this deployed, and can we configure the server to fall back to
index.html?" - "Do we need SSR or SEO for these pages?"
Code / implementation expected: Yes β a router module with a few routes (one lazy, one catch-all), app.use(router), and an App.vue with RouterLink and RouterView.