How to save request parameters in angular 5 along all default routes?

Reference Information:

The user calls the application URL with parameters and uses my application. When switching between different routes, URL parameters should be stored in the address bar of the browser.


I need to save request parameters for each route of my application. That means if I have url

www.example.com/app/test?id=326748798342&state=1

and call the link with [routerLink]="['/login']"I need to get this URL:

www.example.com/app/login?id=326748798342&state=1.

By default, I get an entry route with no parameters. I found one solution that says to install queryParamsHandling='merge'. But this is a very bad decision, because it would mean changing all the links in the templates and all calls to navigate ().

Is there a cleaner way to solve this problem by default? Something like setting queryParamsHandling in an array of routes for the application, or something else?

+4
source share
1 answer

There is currently no way to install it globally. Use queryParamsHandlingseems to be the only option:

<a [routerLink]="['/login']" queryParamsHandling="preserve"></a>

Or when using a router:

router.navigate('/login', { queryParamsHandling: "preserve" })

Another possible option for queryParamsHandlingis merge.

+4
source

Source: https://habr.com/ru/post/1691420/


All Articles