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 trialCarlos Chavez
5,691 PointsIn the Cards.js file, why leave out the /cards when setting the route?
const express = require('express');
const router = express.Router()
router.get('/', (req, res) => {
res.render('card', {prompt: "Who is buried in Grant's Tomb?", hint: "Think about whose tomb it is."})
});
module.exports = router;
I don't understamd the part where he says that we don't have to put the '/cards' route, only '/'.
I tried leaving it unchanged and it thew an error, and when I corrected it back to what he said, it worked fine. The problem is that it doesn;t make sense to me to leave only the root route, and not the one w need.
Thanks anyone for any help :D
2 Answers
Henry Blandon
Full Stack JavaScript Techdegree Graduate 21,521 Pointsbecause in app.js you already have the route
app.use('/cards', cardsRoute);
where cardsRoute is the path to the file.
const cardsRoute = require('./routes/cards');
if have the same name in the cards.js file. It should work. I dint remove mine and it works fine.
router.get('/cards', (req, res) => {
res.render('card', { prompt: "Who is buried in Grant;s tomb?", hint: "Think about whose tomb" });
});
I am not sure what is the best practice on that.
Jonathan Grieve
Treehouse Moderator 91,253 PointsIf I remember rightly it's because there's another file somewhere that makes it so cards routes have their own base route called /"cards". This would be so that each card can be uniquely identified with a url variable. "cards/1/" for example.
Carlos Chavez
5,691 PointsYou're right. I saw it later in the next videos that /route was going to become, so to say, a 'root route' for the cards numbers. I just needed to be patient :P
Thanks Jonathan!