React-router intercepting server routes
See original GitHub issueVersion
4.2.2
Steps to reproduce
Have a server that has an endpoint to be directly navigated to (e.g. /api/logout):
app.get('/api/logout', (req, res) => {
req.logout();
res.redirect('/');
});
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
})
}
Add navigation in the react app like <a href=“/api/logout”> or window.location = ‘/api/logout’
Expected Behavior
A page refresh to the same domain through <a> tag navigation or setting window.location should go through server routing before loading the react app.
Actual Behavior
The correct route request isn’t made to the server and the route is treated as a react-route.
This behavior is only experienced in a production environment. However, there is a strange case where everything works as intended. In firefox private browsing, routing works correctly. In regular firefox, regular chrome, and incognito chrome, routing is not working, as described above.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
React-router intercepting server routes · Issue #5520 - GitHub
The correct route request isn't made to the server and the route is treated as a react-route. This behavior is only experienced in...
Read more >React Router doesn't intercept an HTTP/S request
React -router will "intercept", so to speak, any calls and subsequently perform the client side routing. There wouldn't be a server call for ......
Read more >Example: React Router: Preventing Transitions.
React Router - Preventing Transitions. A simple example deployed using react-codesandboxer. 293. 0. 0. Edit Sandbox. Files. example.js. index.html. index.js.
Read more >Hookrouter: A Modern Approach to React Routing
Routing in React applications using the Hookrouter Routing is essential for Single Page Applications (SPAs) to navigate through pages and to ...
Read more >React Router Version 6 Tutorial – How to Set Up Router and ...
In React, the page contents are created from our components. So what React Router does is intercept the request being sent to the...
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

@pshrmn @timdorr I fixed things by removing the registerServiceWorker() from the create-react-app boilerplate.
Removed registerServiceWorker and unregister fix this issue, what this registerServiceWorker do to fuck everything?