-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
"Warning: Automatically setting basename using <base href> is deprecated" errors #3387
Comments
Please follow the guidelines on https://github.com/reactjs/react-router/blob/master/docs/guides/MinimizingBundleSize.md#import-from-react-routerlib. I'm thinking about lazily initializing the history objects by using a membrane, but that's some ways away. |
Should be fixed by remix-run/history#283 (or maybe #3388 here) at some point, though. |
Thanks @taion - this presents a good excuse to try and get Webpack 2 tree-shaking working, and if not then it is a good to know it should be fixed at some point. |
I didn't have any luck with the tree-shaking route, unless I've missed something - although I've confirmed Webpack is loading the |
It's quite possible we were too optimistic initially about how tree-shaking semantics work out. Let's see if we can get a history 2.1.1 with a patch released that doesn't warn until the initial listen. |
Yeah, I think that might be what is going on. For now I am using the direct On 27 April 2016 at 12:50, Jimmy Jia [email protected] wrote:
|
So with this new solution, is the approach to use |
@ochowie, yes, for now this is the solution (and make sure you only directly import the modules you need from react-router). Would be nice if browserHistory accepted options I agree!
|
With history 2.1.1, the warning should no longer be present if you do import { browserHistory } from 'react-router' For minimum bundle size you shouldn't do this. And for the time being, you will need to use the custom history code path if you need a |
@taion I have history 2.1.1 and react-router 2.3.0 and I'm getting that warning when I do |
The feature is actually deprecated. You need to create a custom history if you want to use |
I'm using the tag because I'm serving from Nginx and from what I've
|
I'm not sure what you mean. If you need useRouterHistory(createBrowserHistory)({ basename }) Otherwise you'll have to elaborate on what you're trying to do. |
So at this point I think it's more of a documentation question. In the
|
I don't understand why Nginx requires a base tag. The reason we deprecated this feature was because the semantics on |
Seems like this wasn't necessarily a react-router or nginx issue. I was using a relative path for my bundled script rather than an absolute path and that was why I would get an error if I wasn't using the base tag. Since I can use absolute paths right now I'm good, but that might not be true or desired in all cases. Sorry if this wasted your time. |
Why was this issue closed? The consensus seemed to be that import { browserHistory } from "react-router"; would indeed prevent the warning, but also that this is obviously just a workaround, as it leads to problems that are far worse than a mere warning in dev mode (increased bundle size, unused variables, thus linting issues, …). Would you agree to re-open this issue until the problem is fixed, be it just to keep track of it? |
That was not the consensus. The fix was related to additionally removing the warning if using that form without a However, using |
I do provide a custom history in my application, but my team still needs
Wait; wasn't the issue that @tomduncalf described exactly that the warning still persists even if a custom history is created? Because that's what I'm still observing in the current stable. |
No, that's a separate issue. If you're using |
Thanks, but I'm not sure if this does what I want; in our scenario, |
Then you're using a basename anyway, and you should set it in your custom history. |
I'm getting the feeling we're talking at cross-purposes. 😄 |
Check that you're importing and setting up your history appropriately. Otherwise, reinstall and make sure you're using the correct version of history. |
@taion After I add the following code: I get the following error: I tried importing "createHistory from react-router, but that didn't work. Do you know how I should move forward? |
@chrisg220 |
createHistory is no longer a function from 'history'. (v4) Also what versions of both the router and hist |
Downgraded history to v2.1.2 and all seems to be working fine. No more annoying error. |
I'm still getting the above issue.. can someone tell me if theyve got a solution here.. Tried the ones above but to no avail. |
First rm-rf node_modules. Then createHistory will be a function. |
Version
2.0.0
Test Case
https://github.com/tomduncalf/react-router-base-issue (issue is not reproducable in JSBin, attempted at http://jsbin.com/poqige/edit?html,js,output, so I suspect the issue is related to ES6/Babel/webpack module bundling/loading somehow)
Steps to reproduce
<base href="http://whatever">
tag to the head of a page containingreact-router
's HTML using the defaultbrowserHistory
history.js
will output 2 errors,Warning: Automatically setting basename using <base href> is deprecated and will be removed in the next major release. The semantics of <base href> are subtly different from basename. Please pass the basename explicitly in the options to createHistory
history
wherehistory
isconst history = useRouterHistory(createHistory)({ basename: 'http://whatever' })
, which should fix the problem (as basename is now explicitly passed)Expected Behavior
Console errors do not appear
Actual Behavior
2 console errors still appear
Additional notes
I have done a bit of digging into this, and I believe what is going on is something like:
history
2.x warns if the page has abase
tag and nobasename
option is passed in. However, we are passing abasename
option, so this should not be an issue.However, https://github.com/reactjs/react-router/blob/master/modules/index.js#L31
export
s https://github.com/reactjs/react-router/blob/master/modules/hashHistory.js. Thisexport
(Babel) compiles down to:https://github.com/reactjs/react-router/blob/master/modules/hashHistory.js#L3 contains
export default createRouterHistory(createHashHistory)
https://github.com/reactjs/react-router/blob/master/modules/createRouterHistory.js#L10 creates a new
history
without any options:history = useRouterHistory(createHistory)()
so I guess is where the error comes from(the same is also true of https://github.com/reactjs/react-router/blob/master/modules/browserHistory.js)
So because this
export
is actually animport
then anexport
, theimport
triggers a call tocreateRouterHistory
for the default export ofhashHistory
, which in turn creates a new history without the options we need to pass to it to avoid an error.A few options I can think of are:
history
module end somehow, e.g. by passing a flag to silence these errorsreact-router
, e.g. makehashHistory
export a function that callscreateRouterHistory
rather than calling it directly, or to somehow pass the options throughWould be great to get your input on this, first time I have looked in the
react-router
codebase otherwise I might have dug deeper and tried to fix :)The text was updated successfully, but these errors were encountered: