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

jason limmm
jason limmm
8,004 Points

unable to load the given route parameter

i am unable to load the given route parameter, i think it's because of the order i put my lines of code, if that's the case, i don't really know how to order the line of code.

product.js

const data = require('../data/products.json');
const products = data.products;

router.get('/', (req, res)=>{
    res.render('productslist');
});

router.get('/:id', (req, res)=>{
    res.render('producttemplate');
    const productname = products[req.params.id].productname;
    const productbio = products[req.params.id].aboutme;
    const productinfo ={productname, productbio};
    res.locals.productinfo = productinfo;
});

productslist.pug

extends layout

block content
    h1 products here!!!!!!!
    div.productlist
        a(href="products/0").one phone 1

producttemplate.pug

extends layout

block content
    h1=productinfo.productname
    p=productinfo.productbio

products.json

{
    "data": {
        "title":"products",
        "products":[
            {
                "productname":"aphone 14 pro makintos",
                "aboutme":"i am versatile makapplecomp for the 1941 to now i still been used because of my uh versatile"
            },
            {
                "productname":"phone",
                "aboutme":"idk"
            }
        ]
    }
}