question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Routes not working on production

See original GitHub issue

I’m having trouble finding the source of this issue since I’m not getting any errors even when I package the app with DEBUG_PROD=true. This works perfectly on development but here is how it looks on production:

prodstandard

I’ve had issues like this for a little while and couldn’t figure it out, today I updated to the latest version of the boilerplate and was able to fix a lot of them but I don’t even know how to start on this one. I thought there was something wrong with the history or store but everything is getting passed correctly so it seems fine.

I don’t think this is an issue with the boilerplate itself since it works with the counter example but maybe you can give me an idea to where I can start looking for the source of this issue.

Thank you very much for your time in advance!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
BuckyMalercommented, Feb 15, 2018

@cdiezmoran your paths are updating as expected. You can see for yourself by logging location to the console when your app first loads, then navigate to the Dashboard and log location once more.

The issue you’re having is termed, update blocking, by React Router. React Router depends on the location object to determine what to render. In your case, the location object is updating as expected, but the React Router location-aware components are not re-rendering due to optimizations performed by React. The optimization that I believe is giving you trouble is shouldComponentUpdate, which is used by react-redux, was used by react-apollo, and is used by a number of other 3rd party libraries. In short, your App component is blocking updates.

There are a few solutions available, but the quickest is to use React Router’s withRouter HOC like so:

import { withRouter } from 'react-router'

export default withRouter(connect(mapStateToProps, mapDispatchToProps)(App));

That should take care of your issue. Also, I suggest you use createHashHistory in your production store. I noticed it resolved 2 bugs when I made that change. It resolved a window reload error, and the active menu item didn’t appear active on initial load otherwise.

I recommend reading through update blocking if you need any further details as that documentation is well written.

Your app is super cool! 😄

1reaction
BuckyMalercommented, Feb 13, 2018

I’d be happy to help @cdiezmoran. It would be helpful if I could dig into the code on my local device. Can you provide the commands for me to clone the repo and start the app?

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-router does not work in production and surge deployments
I used react at my front-end(Create-React-App) and an express backend. In dev mode all things works great but when i switched to the...
Read more >
Handling React Routing in Production - Pluralsight
This guide shows how to solve a page not found error you've in a React app that uses React Router or the HTML5...
Read more >
React router page links not working in production : r/reactjs
Hey everyone. So I have a react site where I use react router to link to different pages. It works locally, but when...
Read more >
Why is React Router not working in production? - Quora
React Router is not working in production. ... the routes exists in the code that is running on the browser, but the routes...
Read more >
Routing not working in production build · Issue #23669 - GitHub
I have facing a problem of routing in production build. my project is routing properly if i try to click on the menu...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found