-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
broken path/query params #340
Comments
Same problem!!! When I have a path like |
hey you have to set this param to raw:true in param declaration |
I'm seeing the same issue with @uirouter/angular v5.0.0 |
I created a workaround which mimics AngularJS behaviour (all parameters not encoded at all), therefore this problem disappears (or just masked) export class AppModule {
constructor(private upgrade: UpgradeModule, router: UIRouter) {
// Set for all router parameters raw: true, to mimic AngularJS behaviour.
// There is a problem inside ui-router, when raw: false, params urlencoded when written to the browsers location,
// but not url-decoded when read back, this cause application works unpredictable.
router.stateRegistry.decorator('params', function customParamBuilder(state: StateObject, parent?: BuilderFunction) {
const paramsMap: {[name: string]: Param} = parent(state);
Object.keys(paramsMap).forEach((paramName) => {
paramsMap[paramName].raw = true;
});
return paramsMap;
});
} |
Or alternative solution (better), override Angular's location strategy and force it to decode uri components: @Injectable()
export class CustomPathLocationStrategy extends PathLocationStrategy {
public path(includeHash?: boolean) {
return decodeURI(super.path(includeHash));
}
}
// app.module.ts
@NgModule({
declarations: [
AppComponent,
],
imports: [
UIRouterModule.forRoot({states: routerStates, useHash: false, otherwise: '/'}),
],
providers: [
{
provide: LocationStrategy,
useClass: CustomPathLocationStrategy,
},
],
})
export class AppModule {} |
- fixes urls double and triple encoding some characters when synchronising the state with the current url. - adds a flag on UrlConfig to disable this decoding (for AngularJS which pre-decodes in the $location api) Fixes ui-router/angular#340
hello currently I'm observing a problem on
ui-router/angular
when having a "special" character in my path or query param.Currently I'm using
ui-router/angular
with version 2.0.0, the "newest", however it's also reproducible on older versions, see the hello world plunker that I changed: https://plnkr.co/edit/5zgTiwtTCp05Vce545gsif you click on 'About' you will see a logging output to the browser console.
Normally you should only see
resolve
once, however it will be called twice.this only happens when trying to open a url with
[uiParams]
where one param has a special character (whitespace, etc). the thing is that ui-router correctly decodes the param and I guess that is also the bug.Currently the second time the route gets called the query parameter is encoded, so calling a
transition.params()
will only get the encoded version (I guess that is wrong behavior, too).The bug only happens if you click on a
uiSref
link, not if you reload the browser with the correct url.The text was updated successfully, but these errors were encountered: