Peter Kellner
Peter Kellner

Reputation: 15478

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

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

Upvotes: 4

Views: 7977

Answers (1)

iurii
iurii

Reputation: 4230

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.

Upvotes: 3

Related Questions