Bird
0
0

Which is the correct syntax to navigate with query parameters and a fragment using Angular Router?

easy📝 Syntax Q3 of 15
Angular - Routing
Which is the correct syntax to navigate with query parameters and a fragment using Angular Router?
Athis.router.navigate(['/path'], { query: {id: 1}, fragmentId: 'section' })
Bthis.router.navigate(['/path'], { params: {id: 1}, hash: 'section' })
Cthis.router.navigate(['/path'], { queryParams: {id: 1}, fragment: 'section' })
Dthis.router.navigateByUrl(['/path?id=1#section'])
Step-by-Step Solution
Solution:
  1. Step 1: Recall navigate method options

    Angular Router's navigate method accepts queryParams and fragment keys in options object.
  2. Step 2: Check syntax correctness

    this.router.navigate(['/path'], { queryParams: {id: 1}, fragment: 'section' }) uses correct keys: queryParams and fragment; others use invalid keys or methods.
  3. Final Answer:

    this.router.navigate(['/path'], { queryParams: {id: 1}, fragment: 'section' }) -> Option C
  4. Quick Check:

    Correct navigate syntax = D [OK]
Quick Trick: Use queryParams and fragment keys in navigate options [OK]
Common Mistakes:
MISTAKES
  • Using params instead of queryParams
  • Using hash instead of fragment
  • Passing array to navigateByUrl

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes