You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I upgraded to v4 of React-Router and had to degrade down to version 3. I couldn't find anything in the docs saying this was deprecated? I'll try to look into this further when I get a few.
Plotist, inker, MrKou47, clubajax, jalik and 42 more
IndexRoute would render the same as using exact property.
For example:
constApp=()=>(<div><Routeexactpath="/"component={Home}/></div>)constHome=({ match })=>(<div><h1>Home</h1><Routeexactpath={match.url}component={Ad}/></div>)constAd=()=>(<div>Ad!</div>)
As for browserHistory, now it it import { BrowserRouter } from 'react-router-dom'.
4.0 is a complete rewrite, so you can't simply upgrade your application and change out a few things. You'll need to rethink some of how you use react-router. Not in an earth-shattering way, just in a more idiomatic React way. Trust me, it's good. But you can't really write a codemod for this upgrade 😉
wyze, ConAntonakos, kangze, ZachStoltz, clarketm and 38 morechuanxie, t3chnoboy, roblapp, vcarel, vincentzierigen and 91 morejgentes, matsad3547, gigobyte, oliverbenns, mikechabot and 48 more
@wyze@timdorr first of all thanks for the v4. I have a few questions and I could not find any solutions for this anywhere, so asking here.
In the earlier versions of the react-router, we could push the the URL using browserHistroy.push() method. When you use browserHistroy the query which you pass, will be transformed to the search key in the history object. The below is an example which used to work in earlier versions.
let query = {
reportType: 'summary',
timeZone: 'UTC'
}
I get that the use case for rendering a component when it exactly matches the root is still covered in this change, but what about the other half of the functionality?
For instance, I want to have a section of my app secured, but I would prefer not to have a prefix in the route, so it would look seamless to a user. In this case, I would follow the structure <Route path="/" component={Root}>
(within Root)
<div>
<IndexRoute component={Secured} />
<Route path="about" component={About} />
<!-- more public routes e.g. -->
</div>
This would have skipped rendering of Secured when the path is /about, but this is lost when moving to the "exact" prop as shown above. What would be the equivalent of this functionality?
In the current version (v4), it is not possible to pass the query object to the history.push() method.
Upvoting this question. There is no way to get a working and separated authentication methods - what is the reason of wrapping everything into components? Composition? Do you want to care about your 401 in a component?
The biggest issue for me with that is being unable to declare your interceptors (with redirects) on very beginning of app. Everything must be child of BrowserRouter, or be a React Component.
I had the same problem and I wasted a couple of days to figure it out. This error happens simply because react-router v4 does not have the 'browserHistory'(donno if that's a good thing or not though). I solved the issue by installing v3 like this: npm install react-router@3 --save
xgqfrmsLA, gigobyte, eosarmien, shakhal, ahashem and 4 morehypno2000, msholty-fd and ahashem
Activity
wyze commentedon Mar 14, 2017
IndexRoute
would render the same as usingexact
property.For example:
As for
browserHistory
, now it itimport { BrowserRouter } from 'react-router-dom'
.Here is documentation for BrowserRouter: https://reacttraining.com/react-router/web/example/basic
Also, the IndexRoute implementation could probably be solved using
<Switch />
: https://reacttraining.com/react-router/web/api/Switchtimdorr commentedon Mar 14, 2017
4.0 is a complete rewrite, so you can't simply upgrade your application and change out a few things. You'll need to rethink some of how you use react-router. Not in an earth-shattering way, just in a more idiomatic React way. Trust me, it's good. But you can't really write a codemod for this upgrade 😉
reznord commentedon Mar 20, 2017
@wyze @timdorr first of all thanks for the v4. I have a few questions and I could not find any solutions for this anywhere, so asking here.
In the earlier versions of the react-router, we could push the the URL using
browserHistroy.push()
method. When you use browserHistroy the query which you pass, will be transformed to thesearch
key in the history object. The below is an example which used to work in earlier versions.This will resolve the URL to -
test.com/some_path/?reportType=summary&timeZone=UTC
In the current version (v4), it is not possible to pass the
query object
to thehistory.push()
method.This will resolve the URL to -
test.com/some_path/
How to get this working with v4.
jhill072 commentedon Jul 9, 2017
I get that the use case for rendering a component when it exactly matches the root is still covered in this change, but what about the other half of the functionality?
For instance, I want to have a section of my app secured, but I would prefer not to have a prefix in the route, so it would look seamless to a user. In this case, I would follow the structure
<Route path="/" component={Root}>
(within Root)
This would have skipped rendering of Secured when the path is /about, but this is lost when moving to the "exact" prop as shown above. What would be the equivalent of this functionality?
damianprzygodzki commentedon Jul 20, 2017
Upvoting this question. There is no way to get a working and separated authentication methods - what is the reason of wrapping everything into components? Composition? Do you want to care about your 401 in a component?
The biggest issue for me with that is being unable to declare your interceptors (with redirects) on very beginning of app. Everything must be child of BrowserRouter, or be a React Component.
xgqfrms-GitHub commentedon Jul 23, 2017
react-router & no
IndexRoute
any more<Route exact path="/" component={Home}/>
===
<IndexRoute component={Home}/>
https://stackoverflow.com/questions/42748727/using-react-indexroute-in-react-router-v4
IndexRoute
any more coryhouse/pluralsight-redux-starter#67Kavehbak commentedon Sep 21, 2017
I had the same problem and I wasted a couple of days to figure it out. This error happens simply because react-router v4 does not have the 'browserHistory'(donno if that's a good thing or not though). I solved the issue by installing v3 like this: npm install react-router@3 --save