router.post('/', controller) vs router.route('/').get(controller)

What's the difference between writing routes:

//in this style
router.route('admin').get(getAllAdminsController).post(createAdminController)

and this type of writing:

router.get('admin', getallAdminsController);
router.post('admin', createAdminController);

Upvotes: 0

Views: 131

Answers (1)

Owl
Owl

Reputation: 6853

There's no difference in terms of functionality. The first style is called chained route, and the purpose of it based on the documentation is:

Because the path is specified at a single location, creating modular routes is helpful, as is reducing redundancy and typos

From: https://expressjs.com/en/guide/routing.html#app-route

Upvotes: 1

Related Questions