next-routes icon indicating copy to clipboard operation
next-routes copied to clipboard

Server rendered 404 page

Open highlabs opened this issue 6 years ago • 11 comments

Hi!

I'm trying to use slug in my article page. It's work when I click in article link, but when I enter directly from URL or I reload the page, I get 404 error.

I tried with and without express server using both of examples in next-routes README.

My /routes.js file:

const routes = require('next-routes');

module.exports = routes().add({
  name: 'post',
  pattern: 'posts/:slug-:id([^-]+)',
  page: 'post_public'
});


My server.js file:

const next = require('next')
const routes = require('./routes')
const app = next({dev: process.env.NODE_ENV !== 'production'})
const handler = routes.getRequestHandler(app)
const express = require('express')
app.prepare().then(() => {
  express().use(handler).listen(3000)
})

package.json

{
  "name": "create-next-example-app",
  "scripts": {
    "dev": "node server.js",
    "build": "next build",
    "start": "NODE_ENV=production node server.js"
  },
  "dependencies": {
    "express": "^4.16.4",
    "next": "^7.0.2",
    "next-routes": "^1.4.2",
    "react": "^16.6.3",
    "react-dom": "^16.6.3"
  }
}

Any ideas what I'm doing wrong?

update

Version with error: https://github.com/highlabs/next-routes-test Live url: https://create-next-example-app-bftspwtpwy.now.sh/

highlabs avatar Dec 17 '18 17:12 highlabs

I have the same error, but on production build

anatoliykot avatar Dec 18 '18 16:12 anatoliykot

the same error

dmitrymikheev avatar Dec 19 '18 21:12 dmitrymikheev

I have found my error, it was wrong setup it was - "start": "next start" instead of - "start": "NODE_ENV=production node server.js"

anatoliykot avatar Dec 20 '18 06:12 anatoliykot

the same error

aminkhademian avatar Dec 23 '18 07:12 aminkhademian

This project is dead?

highlabs avatar Dec 26 '18 12:12 highlabs

same error

Victorkangsh avatar Jan 03 '19 13:01 Victorkangsh

You have no backend route that's why it's 404. checkout next tutorial

aluminick avatar Jan 07 '19 11:01 aluminick

Same thing

seawatts avatar Jan 16 '19 05:01 seawatts

anybody got a workaround at least? in my case it works in dev, but not in production, in addition it automatically adds '/' in every url in production

dstrtop1 avatar Mar 07 '19 05:03 dstrtop1

Same issue!

luyx2412 avatar Mar 16 '19 08:03 luyx2412

Same issue!

I solved it by running node server near my nginx on server like as I do it usually on my localhost

dstrtop1 avatar Mar 16 '19 08:03 dstrtop1