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.

[BUG] Custom route name does not take effect with `refine-nextjs-router`

See original GitHub issue

Describe the bug Custom route name does not take effect with refine-nextjs-router.

To Reproduce

  1. Register resource with custom route
{
  name: "foo",
  options: {
    route: "/custom/foo",
  }
}
  1. Create dynamic nextjs pages
pages/custom/[resource]
pages/custom/[resource]/index.tsx
...
  1. Request /custom/foo, the server return 404

Expected behavior The server should return resource page as expected.

Additional context Look at the following codes https://github.com/pankod/refine/blob/69b36225c3d097dfe5f9d915cc81c47a49280a9b/packages/nextjs-router/src/nextRouteComponent.tsx#L36 Nextjs router find resource by comparing resource name and resource.route, but resource.route is changeable.

The following codes worked for me

const resource = resources.find((res) => res.name === routeResourceName); 

Or

const resource = resources.find((res) => res.name === routeResourceName || res.route === routeResourceName); 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
wy-zcommented, Jan 19, 2022

I have now created version 2.6.3. It will be published in ~15 minutes!

By the way, I have an idea for Layout re-render issue. I’ll open a new issue and tag you!

Truly grateful for your kindness. Good luck and great success in the New Year.

2reactions
wy-zcommented, Jan 19, 2022

Hey @wy-z , Thanks for the bug report.

Yes, your solution is nice but when I use something other than resource name as customRoute this solution doesn’t work.

Example;

{
   name: "foo",
   options: {
     route: "/custom/bar",
   }
}

Any ideas on how we can handle this?

Hi @omeraplak , thank you for your support. See https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes

Next.js dynamic routes can be extended to catch all paths by adding three dots (...) inside the brackets. 

For example:

  1. Create dynamic nextjs page
pages/[...resource].tsx
  1. Request /custom/bar, the resource param will be ['custom', 'bar']

So, one possible way is

  1. if the type of resource is string, compare with resource.name and resource.route
  2. if the type of resource is array, splice the strings together (['custom', 'bar']-> '/custom/bar'), and compare with resource.route
Read more comments on GitHub >

github_iconTop Results From Across the Web

Instantsearch hooks: router not getting along with Next.JS
We are trying out a server rendered search implementation with NextJS. All seems okay until we try to add a routing object to...
Read more >
Shallow Routing
You can use shallow routing to change the URL without triggering a new page ... and the page won't get replaced, only the...
Read more >
next/router
We use a Custom App ( pages/_app.js ) for this example to subscribe to the event because it's not unmounted on page navigations,...
Read more >
Routing: Introduction
Next.js has a built-in, opinionated, and file-system based Router. ... The router will automatically route files named index to the root of the...
Read more >
Rewrites - next.config.js
Add rewrites to your Next.js app. ... Note: rewrites in beforeFiles do not check the filesystem/dynamic routes immediately after matching a source, ...
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