I use the location.key in my child components.
The key is by default 6 characters long. For instance doing const history = createBrowserHistory(), then history.location` it looks like this:
Object { pathname: "/one", search: "", hash: "", query: null, key: "rjtd5t" }
However the location property received by children of <Match> looks like this:
Object { params: Object, isExact: true, pathname: "/one", location: Object, pattern: "/one/:pid?" }
location: Object { pathname: "/one", search: "", hash: "", query: null, state: null }
In this location object we see state but its null, I expcted it to be value of the key. Does anyone know if react router v4 plans to get this? Or if there is a way to get it in the props? I know of course I can get this key by going const history = createBrowserHistory(); let cur_key = history.location.key however this is may not match up with the props (due to animation timing etc), that's why I was hoping to get it from prop.
This is already fixed in the v4 branch.
Ah thank you @mjackson ! This is great news I'm really loving this. I am using ControlledBrowserRouter for Redux.
How can I get the fixed version of v4, do I have to wait till gets a release on npm? I am currently using v4.0.0-alpha.6. So in my package.json it looks like this:
"dependencies": {
"react-router": "^4.0.0-alpha.6",
You can be cutting edge but depending on the repo directly, until a new release is cut.
here is the syntax: git://github.com/user/project.git#commit-ish
I believe for this project it would be: git://github.com/ReactTraining/react-router#v4
Thank you @kwelch ! Is there a scheduled release for alpha 7? The notes for alpha 6 say "do not use we have a huge update coming in the next couple of days".
@kwelch may you please help me on how to install git://github.com/ReactTraining/react-router#v4 with npm? I am using create-react-app and was having difficulty. I really badly needed the location key.
See #4358, installing from git is not supported.
I was unaware additional steps were needed to allow for git dependencies and react-router does not support it.
Oh dang thanks so very much for your fast replies! I am newbie to using non-UMD packages. Do you or @mjackson know when the release is for alpha7? The release notes for alpha6 said it was going to be a few days after the alpha6 release - https://github.com/ReactTraining/react-router/releases/tag/v4.0.0-alpha.6
@Noitidart The beta released today. Here are the docs.
Oh my gosh such perfect timing haha! Thank you @kwelch for that note!
Most helpful comment
See #4358, installing from git is not supported.
I was unaware additional steps were needed to allow for git dependencies and
react-routerdoes not support it.