Handling user request / routes in the express framework
Zion Ben Yacov
· March 1, 2016
It seems to be very weird that each time I create a new page or route I need to add it to the app.js
In that case, if I have a website with hundreds of pages, then the app.js will contain lots and lots of code lines just for the routes
Is there any way to do it like MVC, when the code decide which "controller" (in the nodejs way, route) to initial
Post a Reply
|Oldest Newest Rating|
· June 26, 2016
I am also waiting for same answer.
· April 8, 2017
Sorry about the late response, but of course this can be done very carefully through routing. You can map certain paths onto routers. Then within those router files, you can get more specific. If this isn't very clear, here is an example. You have 3 parts to your site: /, /a, /a/s, /b
Here is the main router: path associations are ('/a',RouterName), ('b',RouterName) where both of these routers are the routers located within their own files. Then within a's routing file there would be something containing /s.