Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Express Basics Parameters, Query Strings, and Modularizing Routes Linking Around the Application

Reggie Williams
STAFF
Reggie Williams
Treehouse Teacher

Goodbye route in Linking around the application (end of express basics)

When I place the goodbye route in the index.js file I get a 404 error when the button is pushed. When I put it in Cards.js it works just fine. In the video I never saw the goodbye route moved

I had a similar problem, But What I did to fix this is to copy the "POST /goodbye" route to the card.js

router.get('/:id', (req, res,next) => {

  const {side} = req.query
  const {id} = req.params

  if(side !== 'question' && side !== 'answer') {
    res.redirect(`/cards/${id}?side=question`)
  } 

  const user_name = req.cookies.user_name


  const text = cards[id][side]
  const {hint} = cards[id]

 const templateData = {id, text, user_name}

 if(side === 'question') {
   templateData.hint = hint
   templateData.sideToShow = 'answer';
   templateData.sideToShowDisplay = 'Answer';
 } else if (side === 'answer') {
  templateData.sideToShow = 'question';
  templateData.sideToShowDisplay = 'Question';
 }

 res.render("card", templateData)
})

/// pasted it here
router.post('/goodbye', (req,res) => {
  res.clearCookie('user_name')
  res.redirect('/hello')
})

Basically, I have two "Post /goodbye" route. one in the index.js and another in cards.js