Last active
June 30, 2016 10:12
-
-
Save harmenjanssen/0b35bb6e20f254dba43fdf2878924131 to your computer and use it in GitHub Desktop.
Reduced test-case showing the problem with sharing routes between Router instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <p>This is the homepage.</p> | |
| <a href="<% url('home') %>">A link to myself</a> | |
| <!-- | |
| This will throw an error: "No route found with the name:home" | |
| --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // the app's main point of entry | |
| const express = require('express'); | |
| const app = express(); | |
| const namedRouter = new (require('named-routes')); | |
| namedRouter.extendExpress(app); | |
| namedRouter.registerAppHelpers(app); | |
| app.use('/', require('./routes')); | |
| app.set('views', './views'); | |
| app.set('view engine', 'ejs'); | |
| app.listen(8000, _ => { | |
| console.log('Example app listening on port 8000!'); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // routes.js contains route configuration | |
| // other routes files can be included from here to keep files a bit cleaner | |
| // | |
| // note that I cannot access my app instance from here | |
| const router = require('express').Router(); | |
| const namedRouter = new (require('named-routes')); | |
| namedRouter.extendExpress(router); | |
| router.get('/', 'home', (req, res) => res.render('home')); | |
| module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment