Next-routes: Server rendered 404 page

Created on 17 Dec 2018  路  11Comments  路  Source: fridays/next-routes

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/

Most helpful comment

I have the same error, but on production build

All 11 comments

I have the same error, but on production build

the same error

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

the same error

This project is dead?

same error

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

Same thing

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

Same issue!

Same issue!

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joncursi picture joncursi  路  3Comments

baires picture baires  路  6Comments

dbenfouzari picture dbenfouzari  路  6Comments

ccuilla picture ccuilla  路  6Comments

JiiB picture JiiB  路  4Comments