Bird
Raised Fist0
Angularframework~20 mins

RouterLink for navigation in Angular - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
RouterLink Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What happens when RouterLink is used incorrectly?
Consider this Angular template snippet:
<a routerLink="['/home']">Home</a>

What will be the result when this link is clicked?
Angular
<a routerLink="['/home']">Home</a>
AThe app navigates to the '/home' route as expected.
BThe app throws a runtime error because routerLink expects a string, not an array.
CThe link reloads the entire page instead of navigating within the app.
DNothing happens because routerLink is not a valid attribute.
Attempts:
2 left
💡 Hint
RouterLink can accept both strings and arrays for navigation paths.
📝 Syntax
intermediate
2:00remaining
Which RouterLink syntax correctly navigates to a child route?
You want to navigate to the child route '/products/details'. Which RouterLink syntax is correct?
A<a routerLink="['products/details']">Details</a>
B<a routerLink="'/products/details'">Details</a>
C<a [routerLink]="['/products', 'details']">Details</a>
D<a routerLink="products/details">Details</a>
Attempts:
2 left
💡 Hint
RouterLink array syntax splits path segments by commas.
🔧 Debug
advanced
2:00remaining
Why does this RouterLink not navigate as expected?
Given this template:
<a [routerLink]="['/dashboard']">Dashboard</a>

Clicking the link does not navigate. What is the likely cause?
Angular
<a [routerLink]="['/dashboard']">Dashboard</a>
AThe RouterModule is not imported in the Angular module.
BThe routerLink directive requires parentheses, like routerLink().
CThe path '/dashboard' is invalid because it lacks a trailing slash.
DThe link must use href instead of routerLink for navigation.
Attempts:
2 left
💡 Hint
RouterLink needs RouterModule to work properly.
❓ state_output
advanced
2:00remaining
What is the value of the href attribute rendered by RouterLink?
Given this Angular template:
<a [routerLink]="['/profile', userId]">Profile</a>

and userId = 42, what is the href attribute value in the rendered HTML?
Angular
userId = 42
A"/profile?userId=42"
B"/profile/42"
C"/profile,userId"
D"/profile/"
Attempts:
2 left
💡 Hint
RouterLink builds the URL by joining path segments.
🧠 Conceptual
expert
3:00remaining
Which statement about RouterLink and accessibility is true?
Select the correct statement about using RouterLink for navigation and accessibility best practices.
ARouterLink disables default link behavior, so you must add ARIA labels manually.
BRouterLink automatically manages keyboard focus and ARIA roles for all links.
CRouterLink requires adding tabindex="0" to enable keyboard navigation.
DUsing RouterLink on <a> tags preserves native keyboard navigation and screen reader support.
Attempts:
2 left
💡 Hint

Solution

  1. Step 1: Identify static RouterLink syntax

    For static paths, use routerLink="/path" without square brackets.
  2. Step 2: Check each option

    <a routerLink="['/home']">Home</a> (A) uses array literal as static string, leading to malformed path. <a [routerLink]="/home">Home</a> (B) has invalid binding expression (missing string quotes). <a routerLink=['/home']>Home</a> (C) has wrong brackets syntax without quotes. <a routerLink="/home">Home</a> (D) uses correct static syntax.
  3. Final Answer:

    <a routerLink="/home">Home</a> -> Option D
  4. Quick Check:

    Static link = no brackets [OK]
Hint: Static links use routerLink without square brackets [OK]
Common Mistakes:
  • Using square brackets for static strings unnecessarily
  • Missing leading slash in path
  • Incorrect bracket placement
3. Given the component template:
<a [routerLink]="['/profile', userId]">Profile</a>

and userId = 42, what URL will the link navigate to when clicked?
medium
A. /profile?userId=42
B. /profile/42
C. /profile/userId
D. /profile

Solution

  1. Step 1: Understand array syntax in RouterLink

    Using [routerLink]="['/profile', userId]" creates a URL by joining segments, so it appends userId as a path segment.
  2. Step 2: Substitute userId value

    With userId = 42, the URL becomes /profile/42.
  3. Final Answer:

    /profile/42 -> Option B
  4. Quick Check:

    Array routerLink joins segments with slashes [OK]
Hint: Array syntax adds path segments separated by slashes [OK]
Common Mistakes:
  • Thinking it adds query parameters instead of path segments
  • Using string interpolation inside array incorrectly
  • Ignoring dynamic value substitution
4. Identify the error in this RouterLink usage:
<a [routerLink]="'/dashboard'">Dashboard</a>
medium
A. The binding brackets should be removed for static paths
B. RouterLink cannot be used on <a> tags
C. The path string should not be in quotes inside the binding brackets
D. Missing parentheses around the path

Solution

  1. Step 1: Analyze binding syntax

    Using square brackets means Angular expects an expression. Here, the expression is a string literal with quotes, which is valid but unnecessary for static paths.
  2. Step 2: Correct usage for static paths

    For static paths, remove square brackets and quotes: routerLink="/dashboard".
  3. Final Answer:

    The binding brackets should be removed for static paths -> Option A
  4. Quick Check:

    Static path = no brackets [OK]
Hint: Remove brackets for static string paths [OK]
Common Mistakes:
  • Using quotes inside binding brackets unnecessarily
  • Thinking RouterLink can't be on anchor tags
  • Adding parentheses around path
5. You want to create a navigation link that goes to a user detail page with a dynamic user ID, but only if the ID is valid (non-null). Which is the best way to use RouterLink in the template to handle this condition?
hard

Solution

  1. Step 1: Understand conditional RouterLink binding

    <a [routerLink]="userId ? ['/user', userId] : ['/user']">User Details</a> uses a ternary operator inside the binding to choose the path based on userId validity, which is clean and safe.
  2. Step 2: Evaluate other options

    <a *ngIf="userId" [routerLink]="['/user', userId]">User Details</a> hides the link if userId is falsy, which may be okay but removes the link entirely. <a [routerLink]="['/user', userId || 'default']">User Details</a> uses a fallback string which might not be desired. <a [routerLink]="/user/{{userId}}">User Details</a> uses interpolation inside the binding expression, which is invalid template syntax.
  3. Final Answer:

    <a [routerLink]="userId ? ['/user', userId] : ['/user']">User Details</a> -> Option A
  4. Quick Check:

    Use ternary inside binding for conditional paths [OK]
Hint: Use ternary operator inside [routerLink] for conditions [OK]
Common Mistakes:
  • Using interpolation inside routerLink attribute
  • Hiding link instead of changing path
  • Using fallback strings that may confuse routing
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard