0

I'm not sure what I want to do is correct or not, appreciate any input on how to achieve it.

I have an Angular SPA application. It has to be accessed with a default query parameter called clientcode to determine, which profile to be loaded - i.e. all application data changes according to the client. So the root url for the application looks like follows:

localhost/myapplication/?clientcode=j92muslsu9872n (just an example).

My other routes in the application look like following:

localhost/myapplication/location

localhost/myapplication/personal-info

localhost/myapplication/appointment

The question is, when I navigate back to the root route, I need to retain the query parameter. So that I could do a browser refresh and access the application.

devC
  • 1,384
  • 5
  • 32
  • 56

1 Answers1

0

Do you want to retain the query parameter on every route? Or just retain the information somewhere so that you can use it again when needed?

If the first, then use preserveQueryParams as suggested in your question comments.

If the second, then use a client-side Angular service to store the query parameter information. Then you can read the value from the service whenever you need to use it again.

For information on reading query parameters and how to activate a route with query parameters, check out the answer here: Send data through routing paths in Angular

          <a [routerLink]="['/home']"
             [queryParams]="{clientcode: currentClientCode}">
            Home
          </a>
DeborahK
  • 57,520
  • 12
  • 104
  • 129