Skip to content

feat(router): add global and route specific config for queryParamsHan… - #16998

Closed
jasonaden wants to merge 1 commit into
angular:masterfrom
jasonaden:fix_16558_global_config
Closed

jasonaden wants to merge 1 commit into
angular:masterfrom
jasonaden:fix_16558_global_config

Conversation

@jasonaden

Copy link
Copy Markdown
Contributor

…dling

Closes #16558

@jasonaden
jasonaden requested a review from vicb May 24, 2017 18:38
@jasonaden
jasonaden force-pushed the fix_16558_global_config branch 2 times, most recently from cda8788 to e6eb02b Compare May 25, 2017 16:03
@mary-poppins

Copy link
Copy Markdown

The angular.io preview for e6eb02b355837e428dc3e8d28cfca1ae570bcdc9 is available here.

@jasonaden
jasonaden force-pushed the fix_16558_global_config branch from e6eb02b to b2efc40 Compare May 25, 2017 17:43
@mary-poppins

Copy link
Copy Markdown

The angular.io preview for b2efc400de01101a8bb1d83a20fc901ad774114a is available here.

@jasonaden
jasonaden force-pushed the fix_16558_global_config branch from b2efc40 to 222415a Compare May 25, 2017 21:44
@jasonaden
jasonaden requested a review from IgorMinar May 25, 2017 21:49
@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 222415a2b2de9da80bf3e46ed1ec4cd096f314b9 is available here.

@IgorMinar IgorMinar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm for api changes

Comment thread packages/router/src/config.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if targetLinkPartsis really useful. People will ask for the target URL which would be more useable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> pass the target UrlTree

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

del

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

del

@vicb

vicb commented May 26, 2017

Copy link
Copy Markdown
Contributor

LGTM - do we really want this in the router code ?

  • narrow use case,
  • could be done by creating custom directives,
  • or by using <a [routerLink]='...' [queryParam]="userMerge({...})" >

@voithos

voithos commented May 26, 2017 •

Copy link
Copy Markdown
Contributor

Using a custom queryParamsHandling for an individual routerLink will of course work, but if there's a parameter (or several) that should be propagated throughout the site (for linkability, etc), specifying queryParamsHandling for each and every link would be tedious and error-prone. This is the intended use case.

Creating custom routerLink directives for this could work, but reimplementing parts of the router seems like something that should be avoided (we'd have to maintain it, etc).

Not sure what you mean by "narrow use case".

@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 1c3f06910418566eba8dcdaeec52c8f5c8a2ca07 is available here.

@jasonaden
jasonaden force-pushed the fix_16558_global_config branch from 1c3f069 to 48783fd Compare May 26, 2017 23:52
@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 48783fdb1357c45173e58afd75950fc40ceba2d5 is available here.

@jasonaden
jasonaden force-pushed the fix_16558_global_config branch from 48783fd to 392be5e Compare May 27, 2017 00:37
@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 392be5ecc3addc39eae7fa4857a32458ece7501a is available here.

@jasonaden
jasonaden force-pushed the fix_16558_global_config branch from 392be5e to 59e791e Compare May 27, 2017 01:42
@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 59e791eaa468cc54ba0eb2c92a624e1c5cb769d6 is available here.

@jasonaden

Copy link
Copy Markdown
Contributor Author

@vicb I updated this PR to expose the logic we use to deal with merging of query params. This way we aren't really adding code to the router, but allowing users to configure the way they deal with query params.

I think this is a preferable way to address this issue. It allows users to get a hold of the default behavior and wrap it with their own behavior. It makes the use case from #16558 easily fixable, as well as future-proofs us for other requests to change this behavior.

@jasonaden
jasonaden force-pushed the fix_16558_global_config branch from 59e791e to 81cb1bc Compare May 30, 2017 17:47
@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 81cb1bc99338a3a271da5bc47e53289ce226fcfa is available here.

Comment thread packages/router/src/config.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o2/o/key ?

Comment thread packages/router/src/config.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export ?

Comment thread packages/router/src/router.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NavigationExtras does not have currentParams neither targetParams

Comment thread packages/router/src/config.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case 'replace'

Comment thread packages/router/src/config.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Does it makes sense to pass the full NavigationExtras here ?
  • I still think that users will ask the current & next route once this PR is merged

Comment thread packages/router/src/config.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Predicate" implies returns a boolean to me ? (I'm not a native speaker)

Comment thread packages/router/src/router.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

queryParamsHandling = queryParamsHandling != null ? queryParamsHandling : this.queryParamsHandling;

and pass only the needed params to the predicate predicate(params, {queryParamsHandling, ...})

would make the code easier to follow

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to pass all the data to the strategy function (it should have been called strategy rather than predicate). This way we don't need to answer user's questions later about why we didn't pass something like the fragment or some such other property defined in NavigationExtras.

Comment thread packages/router/src/router.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const predicate = queryParamsHandlingPredicate || this.queryParamsHandlingPredicate;

Comment thread packages/router/src/router_module.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!= null - because of ''

@vicb

vicb commented May 30, 2017

Copy link
Copy Markdown
Contributor

@voithos by "narrow use case" I mean very specific to your app. If you configure a global merging, it will be used for all navigations/links regardless your origin and destination routes. It becomes easy to keep accumulating all parameters you ever encounter once.

@jasonaden the current implementation seems reasonable to me (se my inline comments) - my only concern is still that users have no way to know source/target routes in the "predicate" and that's probably one thing they will ask next.

@jasonaden
jasonaden force-pushed the fix_16558_global_config branch 3 times, most recently from 9910403 to 3f6aea0 Compare May 30, 2017 21:52
@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 1119cc6b252c07ec2b802715a9e806246da0fcd0 is available here.

@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 9910403b9cec0d8cf02ccec04023ed3b85fef781 is available here.

@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 3f6aea0c4e100ef6f96138bda86a4404f17e62a2 is available here.

@jasonaden
jasonaden force-pushed the fix_16558_global_config branch from 3f6aea0 to 4acb9a1 Compare May 30, 2017 22:49
@mary-poppins

Copy link
Copy Markdown

The angular.io preview for 4acb9a1 is available here.

@jasonaden

Copy link
Copy Markdown
Contributor Author

@voithos Based on discussions with the team, we aren't going to merge this one. Basically, this new API only provides a piece of what will likely be wanted by the community, and providing the extra data (current route, target route, etc) isn't possible at this time. Rather than publishing an API that only partially solves the problem, a workaround for your specific use case should be used. Options would include, but aren't limited to:

  • Create your own directive that can inject a service to merge the params (based on RouterLink)
  • Wrap the Router so that it merges the params before calling Router.navigate using the same service

If there are more users interested in this type of functionality, we will revisit this and see if there's a way to provide a more full-featured API.

@julianpoemp

Copy link
Copy Markdown

If there are more users interested in this type of functionality, we will revisit this and see if there's a way to provide a more full-featured API.

Hello,
I'm now in a situation when I need this feature. In my scenario the user opens my app via URL. This URL cointains parameters that should be preserved on any route of my app. The reason is that the user could copy the URL and share it to other Users.

Adding the [queryParamsHandling]='preserve' to all tags isn't a proper solution.

What I'm looking for is a way to set queryParamsHandling globally. One idea would be to set queryParamsHandling as Attribute to the routes Array. Something like that:
{ path: 'test', component: TestComponent, queryParamsHandling: 'preserve' }
That would mean that a route to 'test' wouldn't reamove the URL parameters.

I already posted on stackoverflow:
https://stackoverflow.com/questions/47995412/how-to-keep-query-parameters-in-angular-5-on-all-routes-by-default

@mlc-mlapis

Copy link
Copy Markdown
Contributor

If there are more users interested in this type of functionality, we will revisit this and see if there's a way to provide a more full-featured API.

For us any way that enables to set queryParamsHandling globally will be welcomed.

@dmattsson

Copy link
Copy Markdown

This would be very useful for us too

@matthew-a-thomas

Copy link
Copy Markdown

This would be useful for me, too

@jericdeleon

Copy link
Copy Markdown

as the app size grows, our use case for this grows as well

@muliyul

muliyul commented Nov 22, 2018

Copy link
Copy Markdown

If there are more users interested in this type of functionality, we will revisit this and see if there's a way to provide a more full-featured API.

Hello,
I'm now in a situation when I need this feature. In my scenario the user opens my app via URL. This URL cointains parameters that should be preserved on any route of my app. The reason is that the user could copy the URL and share it to other Users.

Adding the [queryParamsHandling]='preserve' to all tags isn't a proper solution.

What I'm looking for is a way to set queryParamsHandling globally. One idea would be to set queryParamsHandling as Attribute to the routes Array. Something like that:
{ path: 'test', component: TestComponent, queryParamsHandling: 'preserve' }
That would mean that a route to 'test' wouldn't reamove the URL parameters.

I already posted on stackoverflow:
https://stackoverflow.com/questions/47995412/how-to-keep-query-parameters-in-angular-5-on-all-routes-by-default

We're also interested in this feature

@namse

namse commented Jan 31, 2019

Copy link
Copy Markdown

I need this option. fixing every routes or making own route directives is crazy, please revisit this issue @jasonaden

@conrado-l

Copy link
Copy Markdown

If there are more users interested in this type of functionality, we will revisit this and see if there's a way to provide a more full-featured API.

Hello,
I'm now in a situation when I need this feature. In my scenario the user opens my app via URL. This URL cointains parameters that should be preserved on any route of my app. The reason is that the user could copy the URL and share it to other Users.

Adding the [queryParamsHandling]='preserve' to all tags isn't a proper solution.

What I'm looking for is a way to set queryParamsHandling globally. One idea would be to set queryParamsHandling as Attribute to the routes Array. Something like that:
{ path: 'test', component: TestComponent, queryParamsHandling: 'preserve' }
That would mean that a route to 'test' wouldn't reamove the URL parameters.

I already posted on stackoverflow:
https://stackoverflow.com/questions/47995412/how-to-keep-query-parameters-in-angular-5-on-all-routes-by-default

We are having the same issue, using queryParamsHandling manually in every routerLink or in every router.navigate execution is really error prone.

Being able to set the parameters globally in every route change would make a great feature.

@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Oct 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow global configuration of queryParamsHandling