0
0
Angularframework~5 mins

RouterLink for navigation in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is RouterLink used for in Angular?

RouterLink is a directive that lets you navigate between different views or pages in an Angular app by linking to routes defined in the router configuration.

Click to reveal answer
beginner
How do you use RouterLink in a template to navigate to a route named 'home'?

You add [routerLink]="['/home']" to an anchor tag like this: <a [routerLink]="['/home']">Home</a>. Clicking it navigates to the 'home' route.

Click to reveal answer
intermediate
What is the difference between using routerLink and a normal href for navigation?

routerLink changes the view without reloading the whole page, keeping the app fast and smooth. href reloads the entire page, which is slower and loses app state.

Click to reveal answer
intermediate
How can you pass route parameters using RouterLink?

You pass parameters as part of the array, for example: [routerLink]="['/product', productId]". This navigates to a route like '/product/123' if productId is 123.

Click to reveal answer
intermediate
What attribute can you use with RouterLink to add CSS classes when the link is active?

You use routerLinkActive to add CSS classes when the linked route is active. Example: <a [routerLink]="['/home']" routerLinkActive="active">Home</a>.

Click to reveal answer
What does [routerLink]="['/about']" do in an Angular template?
AReloads the entire page and goes to '/about'
BNavigates to the 'about' route without reloading the page
CCreates a button that submits a form
DAdds a CSS class named 'about'
How do you pass a parameter '42' to a route named 'item' using RouterLink?
A[routerLink]="['/item?id=42']"
B[routerLink]="['/item']" param="42"
CrouterLink="/item/42"
D[routerLink]="['/item', 42]"
Which directive adds a CSS class when the linked route is active?
ArouterLinkActive
BrouterLinkClass
CactiveLink
DrouterActive
What happens if you use a normal href instead of routerLink in Angular navigation?
AIt throws an error
BAngular intercepts and navigates without reload
CThe page reloads completely
DNothing happens
Which of these is the correct way to write a RouterLink for the root path?
A[routerLink]="['/']"
B[routerLink]="['home']"
CrouterLink="root"
D[routerLink]="['root']"
Explain how RouterLink helps in navigating between pages in an Angular app without reloading the page.
Think about how single-page apps work.
You got /4 concepts.
    Describe how to pass parameters to routes using RouterLink and how to highlight active links.
    Focus on syntax and styling active links.
    You got /4 concepts.