question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Server rendered 404 page

See original GitHub issue

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/

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:7
  • Comments:11

github_iconTop GitHub Comments

10reactions
highlabscommented, Dec 26, 2018

This project is dead?

4reactions
anatoliykotcommented, Dec 18, 2018

I have the same error, but on production build

Read more comments on GitHub >

github_iconTop Results From Across the Web

404 Not Found Pages | Error Handling - YouTube
404 Not Found Pages Error Handling Server Server Side Rendering with React and ReduxSubscribe ...
Read more >
How to return 404 page for a server-side rendered dynamic ...
I'm working on a next.js project with Contentful as Content Management System. I want to return the 404 page for a server-side rendered...
Read more >
How To Properly Serve 404 Errors on SPAs (with SEO in Mind)
Redirect Broken URLs to a Stand-Alone 404 Page; Inclusion; Exclusion; Isomorphic Rendering; Simple Server Side; Serve a 404 Component ...
Read more >
Return a 404 from a Next.js page render method (ssr + client ...
Allow to render the error page + return the correct error code with SSR. // It is a hack and has the disadvantage...
Read more >
Basic Features: Pages - Next.js
Two forms of Pre-rendering · Static Generation (Recommended): The HTML is generated at build time and will be reused on each request. ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found