tezvyn:

How do you define a basic Vue or Angular route?

AI-drafted, machine-checkedSource: angular.devbeginner
How do you define a basic Vue or Angular route?

Tests SPA routing conventions. Angular: Routes array in app.routes.ts with path and component, provided in bootstrap. Vue: routes array in src/router/index.js passed to createRouter. Red flag: omitting the outlet or placing config in a component.

WHAT THIS TESTS: This question checks two things. First, do you understand the basic contract of a single-page application router: a URL path maps to a specific component and the framework renders that component without a full page reload. Second, do you know the idiomatic file structure and bootstrap wiring for Vue or Angular. Even senior engineers are expected to state these mechanics crisply before moving to advanced topics.

A GOOD ANSWER COVERS: A strong response walks through the configuration in order. For Angular, you create a Routes array where each object has a path string and a component class, such as path users pointing to UsersComponent. You typically place this array in app.routes.ts or directly inside AppModule. You then provide the router either by calling provideRouter in main.ts for standalone components or by importing RouterModule.forRoot in an NgModule. Finally, the root template must include router-outlet so the router has a placeholder to render the matched component. For Vue, you create a routes array with objects containing path and component, usually in src/router/index.js. You then call createRouter and pass the routes along with a history implementation such as createWebHistory. The router instance is installed with app.use(router) in main.js, and the template uses router-view as the render target. Mentioning both frameworks shows breadth, but answering one deeply is acceptable if you state that is your primary framework.

COMMON WRONG ANSWERS: Red flags include defining routes inside a component file instead of a dedicated router configuration, forgetting to declare the outlet in the template, or describing a server-side routing model instead of client-side SPA routing. Another mistake is confusing lazy loading with eager route definitions, for example describing dynamic imports when the question asks for a basic static route. Saying the configuration goes in index.html or in a random service layer also signals a lack of familiarity with framework conventions.

LIKELY FOLLOW-UPS: An interviewer might ask how to handle a default redirect with an empty path, how to read route parameters in the component, or how to guard a route. They may also ask about nested routes or programmatic navigation, since those are natural extensions of basic routing.

ONE CONCRETE EXAMPLE: In Angular, a minimal setup looks like this in app.routes.ts: you import Routes and UsersComponent, then export const routes: Routes equals an array with one object whose path is users and component is UsersComponent. In main.ts, you bootstrap ApplicationConfig with provideRouter(routes). In app.component.html, you place router-outlet. In Vue, inside src/router/index.js you import createRouter and createWebHistory from vue-router, import Users from Users.vue, define const routes as an array with path slash users and component Users, then export default createRouter with history set to createWebHistory and the routes array. In main.js, you import router from the router file and call app.use(router) before app.mount.

Read the original → angular.dev

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.