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

useBasename with <base href> doesn't work due to the full URL being used #138

Closed
jnv opened this issue Nov 13, 2015 · 3 comments
Closed

Comments

@jnv
Copy link
Contributor

jnv commented Nov 13, 2015

History 1.13 introduced <base> tag support in #94, but I have trouble using it.
Say I have a document with <base href="/lorem/"> running on http://localhost:8080.

I can add useBasename like this:

let history = useBasename(createHistory)({
  basename: '/lorem/'
})

And it will work. If I omit basename argument, useBasename reads basename from <base href> attribute. However, href property of base element returns full URL, therefore the resulting behavior is equivalent to this:

let history = useBasename(createHistory)({
  basename: 'http://localhost:8080/lorem/'
})

Since the basename is being matched against pathname, the basename won't be found and won't be stripped from the location.pathname.

I think one way to fix this is to extract (absolute) path from the base.href.

@taion
Copy link
Contributor

taion commented Nov 13, 2015

Ouch! Good catch.

It sounds like you have a pretty good grasp on this problem. Do you want to try putting together a PR and some tests?

@jnv
Copy link
Contributor Author

jnv commented Nov 13, 2015

@taion I would love to, but I am not sure how to handle this best given existing modules. I would like to use parsePath for this, but it triggers a warning when the full URL is passed. I guess I can either reimplement extractPath or remove the warning; what do you think?

@taion
Copy link
Contributor

taion commented Nov 13, 2015

I'd add an off-by-default flag that disables the warning only for this use case.

@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.
Projects
None yet
Development

No branches or pull requests

2 participants