问题
When using next-routes, and turning off default /page routing
useFileSystemPublicRoutes: true
how can you get the root page of a web site to display?
I can't seem to get any base route to work. For example, this route:
routes.add("homeRoute",'/','homePage');
does not seem to may from locahost:3000/
I see an issue here in the repo that I think is similar but with no solution.
https://github.com/fridays/next-routes/issues/228
回答1:
I think instead of useFileSystemPublicRoutes: true
you just need to create a custom server.js
// server.js
const next = require('next');
const routes = require('./routes');
const app = next({ dev: process.env.NODE_ENV !== 'production' });
const handler = routes.getRequestHandler(app);
const { createServer } = require('http');
app.prepare().then(() => {
createServer(handler).listen(3000);
});
and then have a routes.js
// routes.js
const routes = require('next-routes');
module.exports = routes().add({
name: 'homeRoute',
pattern: '/',
page: 'homePage'
});
Run node server.js
and test /
path.
来源:https://stackoverflow.com/questions/52601724/using-next-js-next-routes-how-to-define-a-home-route-for-the-base-web-page