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