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.

404 on dynamic routes or path error using urls

See original GitHub issue

Hello guys,

i’m facing a little problem since many days now and i don’t figure how to fix it.

I have /pages/views/publication/[slug].tsx, when i try to access it using Link or by the direct url link, i got a : Error: The provided as value (/publication/my-super-url) is incompatible with the href value (/views/publication/[slug]);

to access it by Link i use :

<Link href={views/publication/[slug]} as={/publication/${publication.slug}}></Link>

since the error comes from the incompatible href, i tried to change the viewsDir and set it to null and see if i can play with the paths. After setting the path to null and moved my folder to pages/publication/[slug].tsx it works, but i would like to put it in pages/views

my app.controller with viewDir set to null:

    @Get('publication/:slug')
    @Render(`publication/[slug]`)
    public publicationSlug() {}

Version next: 9.5.5 nest-next: 9.3.0 nest: 6.13

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
billalouaalicommented, Dec 31, 2020

After some rework, i found that the issue were coming from the implementation of :

export async function getStaticPaths() {
  const res = await fetch(`${process.env.API_URL}/publications`);
  const publications = await res.json();
  const paths = publications.map(publication => ({ params: { slug: publication.slug } }));

  return { paths, fallback: true }
}

export async function getStaticProps({ params }) {
  const res = await fetch(`${process.env.API_URL}/publications/${params.slug}`);
  const publication = await res.json();
  return {
    props: {
      publication
    },
  }
}

i don’t know why the error talk about path and why this piece of code is defective but what ever… so i replaced it with getInitialProps and everything works as expected.

Thanks for your help and keep the good work 👍

0reactions
kyle-mccarthycommented, Dec 31, 2020

Okay I am having a little trouble helping since I don’t have access to your code.

First, can you look at the example that I provide in the basic example? The immediately relevant files are listed below, but you may want to check and make sure the config is the same (for example I don’t change the viewsDir).

If you still have issues after that, can you provide a minimal example as a git repository detailing the issue? I can clone it then and try to provide some additional help. I won’t be able to immediately do this but should have some free time in the next couple of days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

404 Error with Dynamic Routing #1145 - gridsome ... - GitHub
Try to go to a different page using the links and the page url changes, but no visual changes occur. Look at the...
Read more >
How to handle not found 404 for dynamic routes in Next.js ...
The issue is how to redirect to 404 not found page when I have undefined parameters in requested URL which needed to pass...
Read more >
Dynamic route returning 404 error - Craft CMS Stack Exchange
I ran into a similar problem with categories and routing a while ago and Marion's answer in this thread worked for me.
Read more >
React Router: Handling 404's on Dynamic Routes
For my application, I associated URLs with a landing screen, a profile screen, a list of recipes, and individual recipes. Each one of...
Read more >
404 Error Page when reloading a dynamic page - Elm Discourse
When I refresh my dynamic Page, I get a 404 Error but the route is looking correctly. Now when I open the Page...
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