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.

Dynamic routes not working

See original GitHub issue

Dynamic routes not working for me. I have uncommented and set:

  const items= await fetch(`http://${server.host}/api/items`).then(res => res.json())
  items.forEach(item=> routes.push(
    `/items/${item._id}`
  ))

And I am still redirected to 404 page

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:22 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
frenzzycommented, Sep 4, 2017
/* src/routes/index.js */
// ...
   {
      path: '/items/:id',
      load: () => import(/* webpackChunkName: 'item' */ './item'),
    },
// ...
/* src/routes/item/index.js */
import React from 'react';
import Item from './Item';
import Layout from '../../components/Layout';

async function action({ params, fetch }) {
  const resp = await fetch(`/api/items/${params.id}`); // use your api here
  const item = await resp.json();
  return {
    chunks: ['item'],
    title: item.title,
    component: (
      <Layout>
        <Item {...item} />
      </Layout>
    ),
  };
}

export default action;
Read more comments on GitHub >

github_iconTop Results From Across the Web

NextLink Dynamic Route Not Working When In Dynamic Route
I have an dynamic route which is sitename.com/[username] When I navigate from sitename.com/account to sitename.com/[username] (for example ...
Read more >
Dynamic Routes Details - Next.js
Dynamic Routes Details. Here is some essential information you should know about dynamic routes. Fetch External API or Query Database.
Read more >
Dynamic route is not working with index.js · Issue #123 - GitHub
Describe the problem: Dynamic routing is not able to fetch params with [slug]/index.js. This is what I am doing so far export async...
Read more >
Client-Side Routing In Next.js - Smashing Magazine
Next.js has a file-based routing system in which each page automatically becomes a route based on its file name. This article will guide...
Read more >
Routing in Next.js – How to Set Up Dynamic Routing with Pre ...
In this tutorial, you'll learn how to set up dynamic routing in Next.js. You'll also learn about pre-rendering and why it's important.
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