Using Next.js next-routes, how to define a home route for the base web page?

瘦欲@ 提交于 2021-01-28 11:01:43

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!