fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

404 error on hard refresh of custom route #148

Closed mbj36 closed 6 years ago

mbj36 commented 6 years ago

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 ?

mbj36 commented 6 years ago

Sorry, i configured my server incorrectly

lagivan commented 6 years ago

@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.

jckw commented 6 years ago

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

lagivan commented 6 years ago

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))
stephane-r commented 6 years ago

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

fridays commented 6 years ago

How do you start the server?

stephane-r commented 6 years ago

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');
  });
});