Shared data is not available when using the `withRouteData`
See original GitHub issueAre you reporting a bug?
Yes. Shared data is not available in the props when using the withRouteData
HOC in the build. While running in dev mode it does work as expected.
Environment
react-static -V
: 6.3.2node -v
: v10.11.0npm -v
: 6.4.1- Operating system: macOS
Steps to Reproduce the problem
Base your steps off of any freshly installed react-static template!
- Add to one of the routes, eg.
blog
in the basic template:
sharedData: {
foo: createSharedData({ bar: 'foobar' })
},
- Check the result using:
export default withRouteData(({ posts, foo }) => (
<div>
<h1>It's { foo.bar }.</h1>
[...]
yarn build
which results in:
TypeError: Failed exporting HTML for URL blog (src/pages/blog.js):Cannot read property 'bar' of undefined
Expected Behavior
Successful build with <h1>It's foobar.</h1>
on the blog page
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Unit Test with route data not working on ASP.NET MVC 5 Web ...
It looks like in MVC 5 the Url property is created in a different way. I have introduced this line in my tests...
Read more >react-static/api.md at master - GitHub
First we would use the createSharedData function and pass the data we want to share between our routes. Then in each route, we...
Read more >Ultimate React Router v6 Guide
Now the final way you can share layouts with React Router is by wrapping child Route components in a parent Route that only...
Read more >Dynamic guard redirects with route data in Angular - kirjai
Redirecting. In case the user is not authenticated and not allowed to view the /restricted route, we would like to navigate him somewhere...
Read more >ActivatedRoute - Angular
Provides access to information about a route associated with a component that is ... will not cause the ActivatedRoute.data Observable to emit a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@tannerlinsley after some deep digging I think I found a solution myself! Please let me know if this makes any sense to you. Also, I took the liberty to remove the return value of the prefetch methods as it turned out to be unused and slightly confused as it was before. Another option would be to actually return the merged data form the prefetch method instead of mutating the routeInfo, but I’m afraid that would mean refactoring in quite a few places and way more complicate to make sure it won’t break anything…
No, it should function the original way. This does indeed look like a bug.