Next-routes: 404 error on hard refresh of custom route

Created on 8 Mar 2018  路  7Comments  路  Source: fridays/next-routes

Hey @fridays

Thanks for making this, it's really helpful - Whenever i hard refresh my custom routes, it gives 404 error, when i go through <Link> it just works fine

Any thing which i might be missing ?

Most helpful comment

I was having the same problem, but turns out the solution was really simple: needed to restart the server between switching Git branches. 馃檭

All 7 comments

Sorry, i configured my server incorrectly

@mbj36 I'm facing the same issue. Could you please clarify what exactly was wrong with the server configuration? Maybe I need to apply the same fix.

I was having the same problem, but turns out the solution was really simple: needed to restart the server between switching Git branches. 馃檭

P.S. I've figured it out myself. Adding the following code solved it for me:

const customRoutes = require('./routes/custom')
const expressApp = Express()
expressApp.all('/custom/*', customRoutes.getRequestHandler(app))

Hi guys, i've same issue with default example on the README. Anyone have fallback ?

How do you start the server?

Hi @fridays

If i run my server with node server.js, express return Client pings, but there's no entry for page: /
With next command, all route working, but the hard refresh return an 404 error.

My server.js :

const next = require('next')
const routes = require('./config/routes')
const app = next({ dev: process.env.NODE_ENV !== 'production' })
const handle = routes.getRequestHandler(app)

const express = require('express');

app.prepare().then(() => {

  const server = express();

  server.use(handle);

  server.get('/inscription', (req, res) => {
    return app.render(req, res, '/inscription', req.query);
  });

  server.get('*', (req, res) => {
    return handle(req, res);
  });

  server.listen(3000, (err) => {
    if (err) throw err;
    console.log('Server ready on http://localhost:3000');
  });
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mocheng picture mocheng  路  5Comments

adrianha picture adrianha  路  3Comments

bliitzkrieg picture bliitzkrieg  路  4Comments

jchiellini picture jchiellini  路  4Comments

arefaslani picture arefaslani  路  3Comments