Closed yves-s closed 6 years ago
Ok, I got it:
// routes.js
const routes = module.exports = require('next-routes')();
routes
.add('p', '/p/:slug', 'product')
.add('c', '/c/:slug', 'content')
.add('service', '/service/:slug')
.add('legal', '/legal/:slug');
module.exports.Link = routes.Link;
module.exports.Router = routes.Router;
module.exports = routes;
and I had to add/remove
// server.js
...
- const handle = app.getRequestHandler();
+ const handler = routes.getRequestHandler(app);
...
- server.get('*', (req, res) => {
- return handle(req, res)
- });
server
+ .use(handler)
.listen(3000, (err) => {
if(err) throw err;
console.log('> Ready on http://localhost:3000');
});
This line const routes = module.exports = require('next-routes')();
is an export. You can see module.exports
getting assigned right there.
I'm having issues with this too .. external links to the app throw error 404. Don't know what I'm doing wrong
@mherodev that's right!
@chrisehlee If your getting 404 please check if your starting the app by running node server.js
(instead of next start)
In general it's pretty well documented but the last steps seem to be missing to get it up and running.
Under "How to use" you describe the
routes.js
file setup.But you don't explain how and what to export.
In the section "On the server" there is routes imported/required but we didn't export anything in
routes.js
.If I do every step as explained and export
routes
fromroutes.js
as:I still get an 404 after refresh and my node server (express) doesn't find my defined routes.
Also you explain in "On the client",
Link
should also be used fromroutes.js
but we didn't export that either.Maybe an example would help as well.