ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

I'm trying to use router file to handle app.get() but I got error #171

Open dotku opened 8 years ago

dotku commented 8 years ago

Hi, express-handlebars sample actually runs, but when I convert the app.get() to route file, I got error. Here is my code in /route/index.js

var app = ('../app.js');
app.get('/', function (req, res) {
    res.render('home', {
        title: 'Home'
    });
});

I just take the idea from here: http://stackoverflow.com/questions/25596803/express-4-with-handlebars-add-new-route/25597043#25597043

I also upload my full code to my github branch: https://github.com/dotku/node-study/tree/express_4.x_router

dotku commented 8 years ago

I found the answer: instead using app.get(), the router should use router.get()

'use strict';

var express = require('express');
var router = express.Router();

router.get('/', function (req, res) {
    res.render('home', {
        title: 'Home'
    });
});

module.exports = router;