I have been tasked with creating a website using Angular that can accept direct parameters for a client at the URL level.
For instance, a sales representative will have a website like www.website.com/agent/2021 and customize the site based on their ID (2021 in this example). I have successfully implemented this by configuring the routing module as follows:
{ path: '', component: AgentComponent, pathMatch: 'full' },
{ path: '**', component: AgentComponent },
With the route:
path: 'agent/:code', component: AgentComponent,
Everything is working perfectly, except when navigating to www.website.com directly, it displays a blank page. This is expected behavior because the code in app.component.ts is executed first. I have set up an agent ID 1 in the database so that if someone accesses the URL directly (without a route), they are automatically redirected to www.website.com/agent/1. However, I am struggling to determine whether the user accessed the direct URL or a URL with a route (such as www.website.com/agent/2021).
Is there a solution to detect if the client landed on the URL directly (www.website.com) and redirect them to www.website.com/agent/1, or if the client came from a specific route (www.website.com/agent/2021), keep them on that route?
Thank you.