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

Duplicate Basename #169

Closed
MrEfrem opened this issue Dec 2, 2015 · 3 comments
Closed

Duplicate Basename #169

MrEfrem opened this issue Dec 2, 2015 · 3 comments

Comments

@MrEfrem
Copy link

MrEfrem commented Dec 2, 2015

Hello.
I create history

const history = useQuerys(useBasename(createBrowserHistory))({
  basename: '/test',
});

and uses createPath for building URL:

const path = history.createPath(location.pathname, {...location.query, { param1: test}}));
history.push(path);

Because createPath add basename and history.push add basename, i receive basename/basename/path....

I of course found such solution:

const location = history.createLocation(history.createPath(location.pathname, {...location.query, { param1: test}})));
history.push(location);

but it seems to me not beautifully.
Can add to prependBasename (useBasename.js) the analysis of existence of basename if typeof location === 'string'?

...
function prependBasename(location) {
...
if (typeof location === 'string') {
 location = parsePath(location)
 if (location.pathname.indexOf(basename) === 0) {
          location.pathname = location.pathname.substring(basename.length)
          location.basename = basename
 }
}
...
@taion
Copy link
Contributor

taion commented Dec 2, 2015

Don't use createPath for that. Use the new syntax from #141 once it's out.

@taion taion closed this as completed Dec 2, 2015
@taion
Copy link
Contributor

taion commented Dec 2, 2015

Or just pushState for now, really.

@olmobrutall
Copy link

+1 for the same problem.

In my case passing the object to push or pushState is not really a solution.

I want to return a url from a method that then i can use to put it in a <a href="url"/>, do a windows.open(url) or use a history.push(url).

Why addBasename is good enough for listenBefore, listen or createLocation but not for push, replace, createPath, createHref and createLocation.

https://github.com/rackt/history/blob/master/modules/useBasename.js

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
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

3 participants