Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rc2 Router strips extra arguments from the path after matching a route #11233

Closed
akorchev opened this issue Sep 1, 2016 · 7 comments
Closed

Comments

@akorchev
Copy link

akorchev commented Sep 1, 2016

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

I am trying to implement OAuth2 implicit flow. It redirects to a specified url with a hash appended - #access_token. This is a problem with HashLocationStrategy because it looks for a matching route.
As a workaround I just defined a route that redirects to the root.

{ path: 'access_token', redirectTo: '/' }

Current behavior
In rc2 the router started to strip everything in the URL - for example the value of the access_token.

Expected/desired behavior
In rc1 the router didn't strip anything from the URL and all hashes remained untouched.

Reproduction of the problem
If the current behavior is a bug or you can illustrate your feature request better with an example, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).

What is the expected behavior?

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

  • Angular version: 2.0.0-rc.X
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [all | TypeScript X.X | ES6/7 | ES5]
@zoechi
Copy link
Contributor

zoechi commented Sep 1, 2016

Sounds like an issue to compete with #9786

See also 23ee29b

<a [routerLink]="['/user/bob']" preserveQueryParams preserveFragment>

@akorchev
Copy link
Author

akorchev commented Sep 1, 2016

I see. It makes sense to remove them by default. However there doesn't seem to be a way to specify those options in the route configuration:

{ path: 'auth_token', preserveQueryParams: true, preserveFragment: true }

@vicb
Copy link
Contributor

vicb commented Sep 1, 2016

Your question sounds like a support request.

Please use the issue tracker only for bugs and feature requests.

Use gitter and StackOverflow for support request.

@vicb vicb closed this as completed Sep 1, 2016
@akorchev
Copy link
Author

akorchev commented Sep 1, 2016

I wonder why you think this is a support request. There isn't a single question in this issue.

  1. Upgrading to angular router rc3 broke existing functionality (OAuth authorization).
  2. It turned out to be a fix that has a side effect.
  3. I don't think there is any way now to implement OAuth implicit flow login with angular 2 if I use HashLocationStrategy. Of course I can use PathLocationStrategy but then a browser refresh breaks my app (nothing on the server side to handle the route).

@zoechi
Copy link
Contributor

zoechi commented Sep 1, 2016

@vicb I also think that adding a config parameter to the route config is a valid feature request.

@MattSenter
Copy link

FWIW, I put together a quick and dirty way of ensuring the parameters are always preserved. You just have to override the DefaultUrlSerializer that is configured in the RouterModule.

import {DefaultUrlSerializer} from "@angular/router";
import {UrlTree} from "@angular/router/src/url_tree";

/**
 * Preserves any params passed as part of the hashed route. Normally, these params are annihilated
 * by {DefaultUrlSerializer}, but that is dumb because it prevents things like OAuth2 Implicit
 * grants from succeeding.
 */
export class PreserveHashParamsUrlSerializer extends DefaultUrlSerializer {

  parse(url: string): UrlTree {
    console.debug("[PreserveHashParamsUrlSerializer] Parsing url=" + url);
    let preservedHashParamsUrl = url.replace("&", "?");
    console.debug("[PreserveHashParamsUrlSerializer] Now preservedHashParamsUrl=" + preservedHashParamsUrl);
    return super.parse(preservedHashParamsUrl);
  }
}

Then of course in your app-routing.module.ts or what-have-you, you need to provide PreserveHashParamsUrlSerializer.

...
@NgModule({
  imports: [RouterModule.forRoot(routes, {useHash: true})],
  exports: [RouterModule],
  providers: [
    {provide: UrlSerializer, useClass: PreserveHashParamsUrlSerializer}
  ]
})
...

Note that I am using Angular 5 at this point. Not sure why this isn't a configurable thing.

@angular-automatic-lock-bot
Copy link

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 Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants