TypeError: Router.use() requires middleware function but got a Object

后端 未结 9 1316
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 20:30

There have been some middleware changes on the new version of express and I have made some changes in my code around some of the other posts on this issue but I can\'t get a

9条回答
  •  旧巷少年郎
    2020-11-29 21:20

    I had this error and solution help which was posted by Anirudh. I built a template for express routing and forgot about this nuance - glad it was an easy fix.

    I wanted to give a little clarification to his answer on where to put this code by explaining my file structure.

    My typical file structure is as follows:

    /lib
    
    /routes
    

    ---index.js (controls the main navigation)

    /page-one
    
    
    
    /page-two
    
    
    
         ---index.js
    

    (each file [in my case the index.js within page-two, although page-one would have an index.js too]- for each page - that uses app.METHOD or router.METHOD needs to have module.exports = router; at the end)

    If someone wants I will post a link to github template that implements express routing using best practices. let me know

    Thanks Anirudh!!! for the great answer.

提交回复
热议问题