How to create dynamic routes at Angular 9

Asked

Viewed 44 times

0

I’m having trouble creating dynamic routes, in case my system has customers and each client has a code. Wanted in the url or route, when inform the client code on the route, it fetch the customer data and customize, for example the primary and secondary colors. For example, I have the login route, which would be http://localhost:4200 or http://localhost:4200/login (would be fixed routes). When you enter the client code this way: http://localhost:4200/cliente1 or http://localhost:4200/client1/login already fetch the client data, apply the style and then put "cliente1" in the pathname of the routes. I decided to do the routes like this:

 .
 . 
 .

 const appRoutes: Routes = [
  { path: 'login', component: LoginComponent },
  { path: ':codeinstance/login', component: LoginComponent },
  { path: ':codeinstance', component: LoginComponent },
  { path: '', component: LoginComponent }
 ];

 @NgModule({
   imports: [RouterModule.forRoot(appRoutes)],
   exports: [RouterModule]
 })
 export class AppRoutingModule { }

However, it only works by debugging, as "ng serves", but when a build with a specific href does not work on the server where it will be published or on IIS. I wonder if I am on the right track and how to solve this by publishing the code on the server.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.