Separating Routes?
See original GitHub issueThe example in the README for the server renderer is basically a catch-all route: return (req, res, next) => {
. What if you want to have multiple routes react differently? Do you have to check for the request url and a bunch of if/else statements? Or is there access to app
somewhere that allows you to add other app.use
statements for different routes (or other things, like adding middleware for example)?
Hopefully what I’m asking is clear enough to understand. I’m a node newb so pardon my ignorance.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to separate routes on Node.js and Express 4?
As far as separating routes from main file is concerned.. Server.js //include the routes file var routes = require('./routes/route'); var ...
Read more >Separating logic from Express routes for easier testing
Separating logic from Express routes for easier testing. Have you ever been confused on how to structure your Express applications in a way...
Read more >How to Create Separate Routes File in Node JS Express?
i explained simply about separate file for routes in express node.js. In this tutorial, i will give you two examples of how to...
Read more >Express Tutorial Part 4: Routes and controllers - MDN Web Docs
Defining and using separate route modules. The code below provides a concrete example of how we can create a route module and then...
Read more >Combining and Splitting Routes - Ride with GPS
Premium subscribers can combine multiple routes or split a long route into many using our simple split and combine tools. For advanced route...
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 FreeTop 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
Top GitHub Comments
good to know, thanks for your help. i don’t have an immediate need to do this right now, it was more of a theoretical question for when the need arises, so i’ll try it when that happens. i’ll close the issue for now, thank you.
The router would be returned from your server renderer function, e.g.
However, for any routes unrelated to server side rendering such as a healthcheck (usually any code that doesn’t need to be compiled with webpack) you can just mount them in your main app before you mount the server renderer.