-
Notifications
You must be signed in to change notification settings - Fork 961
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
Transparently support <base href> in HTML documents #94
Comments
@MoOx Would you like to take a shot at a PR here? |
Hi @mjackson. Sorry but I have others priorities atm, I have used a workaround that satisfies my need. Maybe later but I cannot guarantee anything. Anyway, thanks for the work you made! |
I'm running into an issue with the way that react-router automatically detects the base tag. I'm currently using |
What do you mean "ignore the tag"? Are you also passing in |
@talon I'm just using the base tag to enforce the target of all links in the document, but it's having the side effect of causing react-router to consider all paths without a query string to be "/". I meant that the base tag would be ignored for the purpose of automatically setting a basename if there is no href attribute set. I'm not passing a basename to createHistory. I'm using a vanilla |
Sorry, I still don't understand what the problem is. What specifically are you seeing? There is no logic to automatically infer |
It's ok, I could be completely off base here - I haven't done much looking into the actual react-router codebase. According to a9759df react-router automatically uses the href attribute of the base tag if one is found and no explicit basename has been set for the history. I'm assuming this is causing a side effect somewhere, since simply removing the base tag resolves the issue and the issue is not seen when rendering on the server. document.location.pathname is showing the correct pathname of Strangely, simply appending a question mark to the URL seems to resolve the issue as well. |
I see. Thanks. Could you open this as a new issue? Sounds like a bug. |
Hit "comment" too quickly, rewriting this. |
I took a look. The current behavior is just plain wrong. For an empty The real problem is that if we have something like Unfortunately, we can't fix this with the current API. The expedient thing to do would be to update https://github.com/mjackson/history/blob/v2.0.1/modules/useBasename.js#L18 to use |
And in the router context, this qualifies as a silly obnoxious inconsistency. I think we should just get rid of |
One option is to use a custom attribute like |
@mjackson wdyt of using something like |
@taion I don't see why we can't fix this with the current API. If |
Sorry, what I mean is – we can continue to support If we have If we have In other words, our transparent support for |
Ah, I see. Thanks for clarifying. In that case it does seem like we should just drop support for |
That's technically true but it might not matter much in practice. In the case where For relative links, I think it'd make the most sense for them to be relative to the route tree anyway, and otherwise ignore It might matter for relative transitions in history, e.g. for something like I do think it might be nice to invent a |
Ok, sounds like the best way forward is to deprecate and remove |
We might want to fix the React Router examples then: https://github.com/reactjs/react-router/blob/v2.2.4/examples/active-links/index.html. |
This is going way off-topic, but what do you think of the idea of enhancers that can take an already-created history? Something like useRouterHistory(createBrowserHistory)({ basename })` we could just do something like: withBasename(browserHistory, basename) or something along those lines. Same with |
A function that accepts a createHistory function, rather than a history I like the withBasename example you gave. I think it's worthwhile to On Mon, Apr 18, 2016 at 10:02 AM Jimmy Jia notifications@github.com wrote:
|
Now that we have
useBasename
, it would be neat if we could transparently support HTML documents that use the<base>
element to set a base URI for all relative links on a page. It could be part ofcreateDOMHistory
, or possibly its own history enhancer.See remix-run/react-router#2014 for previous discussion.
The text was updated successfully, but these errors were encountered: