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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Kevin Becerra](https://secure.gravatar.com/avatar/af5f84da126cde5e5dfd5244b2683bf0?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Kevin Becerra
14,243 PointsOnly able to get page to load by using whole route when I should be able to use '/:id'
This is the app.js and card.js I know the file structure is correct I don't know what would be causing this
card.js
const express = require('express');
const router = express.Router();
const { data } = require('../data/flashcards.json');
const { cards } = data
router.get('/:id', (req, res) => {
res.render('cards', {
prompt: cards[req.params.id].question,
hint: cards[req.params.id].hint,
});
});
module.exports = router;
App.js
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const app = express();
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: false }));
app.set('view engine', 'pug');
const mainRoutes = require('./routes');
const cardRoutes = require('./routes/cards');
app.use(mainRoutes);
app.use(cardRoutes);
app.use((req, res, next) => {
const err = new Error('URL not found');
err.status = 404;
next(err);
});
app.use((err, req, res, next) => {
res.locals.error = err;
res.status(err.status);
res.render('error');
});
1 Answer
![Zimo Dong](https://secure.gravatar.com/avatar/13c3412762b8c7771ddd5473dd8faa7d?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Zimo Dong
Full Stack JavaScript Techdegree Student 10,755 Pointsinstead of app.use(cardRoutes); try app.use('/cards', CardRoutes); //the path param means that every route in our cards.js start with /cards