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

Location Service not working with hash #747

Closed
bouncehead13 opened this issue Mar 24, 2020 · 0 comments · Fixed by #814
Closed

Location Service not working with hash #747

bouncehead13 opened this issue Mar 24, 2020 · 0 comments · Fixed by #814

Comments

@bouncehead13
Copy link

Use Case

We are trying to set the UI Params to include both state params and a hash. An example would be

/shop?page=1#fruit=orange

Problem

The _set function within the Ng2LocationServices is not properly parsing the hash before sending it along to the Angular Path Location Strategy.

The function assumes the hash can be prepended to the URL always which is not the case when we combine state params with a hash. The incorrect output from this would be

/shop#fruit=orange?page=1

Suggested Fix

I'm not entirely sure why the code currently assumes the hash should always be prepended to the path, but may this be a potential solution.

let urlPath;
let urlParams;

const { path, search, hash } = parseUrl(url);
if (search) {
    urlPath = path;
    urlParams = search + (hash ? '#' + hash : '');
} else {
    urlPath = path + (hash ? '#' + hash : '');
    urlParams = search;
}

if (replace) {
    this._locationStrategy.replaceState(state, title, urlPath, urlParams);
} else {
    this._locationStrategy.pushState(state, title, urlPath, urlParams);
}

The main suggestion here is if we have search params, append the hash to the search not the path. If there are no search params, then do what exist currently and append the hash to the path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant