router not defined with custom express server
See original GitHub issueEver since I added custom Express server to handle clean URLs, withRouter HOC doesn’t inject props.router.
Navigating FROM a page where withRouter is not used, TO a page withRouter, router prop is present, however, if the page is refreshed, the router prop is gone.
This is my current server.js setup for the clean urls.:
server.get('/c/learn/:courseSlug/:lessonSlug', (req, res) => {
const actualPage = '/course/learn';
const queryParams = {
courseSlug: req.params.courseSlug,
lessonSlug: req.params.lessonSlug
};
app.render(req, res, actualPage, queryParams);
});
How to user withRouter and Router methods with clean URLs?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Why this route is working in express when not defined ...
it means express will use or any request that comes with '/' - will be redirected to route defined on route/index page router.use("/user" ......
Read more >router not defined with custom express server · Issue #7582
Ever since I added custom Express server to handle clean URLs, withRouter HOC doesn't inject props.router . Navigating FROM a page where ...
Read more >Express/Node introduction - Learn web development | MDN
This object, which is traditionally named app , has methods for routing HTTP requests, configuring middleware, rendering HTML views, registering ...
Read more >Writing middleware for use in Express apps
The next function is a function in the Express router which, when invoked, executes the middleware succeeding the current middleware.
Read more >Advanced Features: Custom Server - Next.js
Before deciding to use a custom server, please keep in mind that it should only be used when the integrated router of Next.js...
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

@ScottAgirs You need to change the import from
to
The default export is the one with
withRouter(). btw if you’re usingNowthen you don’t need the custom server you currently have, instead you can have a serverless build and add custom routes tonow.jsonlike here.https://bitbucket.org/ScottAgirs/ijstobe/src/master/
https://bitbucket.org/ScottAgirs/ijstofe/src/master/
The Component at stake is
ijstofe/src/components/SingleCourseLearn.jsjust noticed thatijstofe/src/components/SingleCourse.jsworks fine with Router and/or withRouter.