1

I need to add some kind of global routing parameter in my Angular application.

I need different clients to use one site depending on the link they entered from.

For example: https://myrandomsite/client1/sessions/login https://myrandomsite/client2/sessions/login https://myrandomsite/client3/sessions/login

I have this in app.routing

 {
    path: '', 
    component: AuthLayoutComponent,
    children: [
      { 
        path: 'sessions', 
        loadChildren: () => import('./views/sessions/sessions.module').then(m => m.SessionsModule),
        data: { title: 'Session'} 
      }
    ]
  }

And in my session.routing

export const SessionsRoutes: Routes = [
  {
    path: "",
    children: [
      {
        path: "signup",
        component: SignupComponent,
        data: { title: "Signup" }
      },

I can add an :id before every child module like path: "client-name:/signup", but want it at the start of the route throughout the application.

Or any other suggestions on how I can accomplish this will be appreciated.

  • Does this answer your question? [Angular 2 optional route parameter](https://stackoverflow.com/questions/34208745/angular-2-optional-route-parameter) – Marshal Nov 09 '20 at 19:34
  • No not exactly. I do load components like that. I want the id at the start of the path for a specific client of mine. So the signup should be https://domainname/testsite/sessions/signup where testsite could be any client of mine and there would (hopefully) be hundreds of them and their clients can signup to their site but I would only need to manage one website. For now I made the signup path = path: ":siteName/signup" and save the siteId on registration and set it in a cookie when the user log in and check auth in the backend. – Christo Fourie Nov 09 '20 at 20:09

1 Answers1

1

You could create separate env for each client then in the route you can use these env to provide url :)

ravciok
  • 71
  • 3