Create a template link to a route without a full page reload
Tests SPA client-side routing knowledge. Strong answer: name RouterLink or routerLink, explain click interception and History API URL updates, and contrast with plain anchor tags.
WHAT THIS TESTS: This question checks if you know how single-page applications handle navigation without server roundtrips. The interviewer wants to see that you understand the difference between a standard browser link and a framework router link, and that you can name the correct syntax for your chosen framework.
A GOOD ANSWER COVERS: First, name the specific component or directive. In Vue, use the RouterLink component with a to prop, like RouterLink to='/about'. In Angular, use the routerLink directive on an anchor tag, like a routerLink='/about'. Second, explain the mechanism. The framework link intercepts the native click event, calls preventDefault, and uses the History API to push a new URL state. This keeps the current page alive and swaps components via RouterView or router-outlet instead of fetching a new HTML document from the server. Third, contrast it with a plain anchor tag. A standard a href='/about' triggers a full browser navigation, causing the server to respond with a fresh page and losing all client-side state including any in-memory store or form data. Fourth, mention practical benefits. Router links handle active state styling, URL encoding, and relative path resolution automatically so you do not have to manage those concerns manually.
COMMON WRONG ANSWERS: Saying you would just use an a tag with an href attribute and claiming the SPA framework prevents the reload automatically. That is incorrect; the browser performs a full navigation unless the framework link component or directive intercepts it. Another red flag is confusing programmatic navigation with declarative links, or mentioning router.push when the question specifically asks for template syntax. Mixing up Vue RouterLink syntax with Angular routerLink syntax, such as putting to on an Angular element, also signals shallow familiarity.
LIKELY FOLLOW-UPS: How would you pass dynamic route parameters or query strings in the link? What happens if a user right-clicks and opens the link in a new tab, and how does the router still support that behavior? How does the router know where to render the matched component? What is the difference between named routes and literal paths in the link declaration? When would you choose programmatic navigation over a declarative router link?
ONE CONCRETE EXAMPLE: In Vue 3 with Vue Router 4, the syntax inside a template is an opening RouterLink tag with to='/users', the text Users, and a closing RouterLink tag. When clicked, Vue Router updates the browser address bar to /users, matches the route in your configuration array, and renders the corresponding component in the RouterView placeholder. The browser never requests a new page from the network.
Read the original → router.vuejs.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.