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 Deeper into Routing with Express Redirects

Redirect is not working

The code below is not working

app.use(bodyParser.urlencoded({extended:false})) app.use(cookieParser()) app.set('view engine','pug');

app.get('/', (req , res)=>{ var name = req.cookies.username res.render('index',name); });

app.get('/Cards', (req , res)=>{ res.render('card', { prompt: "Who is buried in the tomb?" , hint:"Search for the name of the tomb"}); });

app.get('/hello', (req , res)=>{ res.render('hello'); });

app.post('/hello', (req , res)=>{ res.cookie('username' , req.body.username); res.redirect('/'); });

1 Answer

Matt Roger
Matt Roger
15,066 Points

You might have an error in your pug files, but I did notice that you have a mistake. However it shouldn't affect the redirect

in your app.get('/'... you have res.render('index', name), it should be ('index', {name})