1.

Does the following code have any errors? If yes, what is the error and how are you supposed to correct it? If not, which component (User,Admin,Customer) is going to be invoked when ‘/user/:name’ is navigated to.

Answer»

No, the code does not have any error, but SOMETIMES the URL might be matched by multiple routes, and the CONFUSION of which path needs to be MAPPED can be resolved by route matching priority. The priority is based on the ORDER of route configuration. i.e., The route which is declared first has higher priority. 

  • In our case, the URL (/user/:name) is assigned multiple COMPONENTS (User, Admin, and Customer) to be routed, which creates confusion. 
  • Since route matching priority is based on the order in which the routes were defined, the first component,' User,' will be invoked, and the other two ways are left unconsidered. 


Discussion

No Comment Found

Related InterviewSolutions