[BUG] Custom route name does not take effect with `refine-nextjs-router`
See original GitHub issueDescribe the bug
Custom route name does not take effect with refine-nextjs-router
.
To Reproduce
- Register resource with custom route
{
name: "foo",
options: {
route: "/custom/foo",
}
}
- Create dynamic nextjs pages
pages/custom/[resource]
pages/custom/[resource]/index.tsx
...
- Request
/custom/foo
, the server return404
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:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Truly grateful for your kindness. Good luck and great success in the New Year.
Hi @omeraplak , thank you for your support. See https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes
For example:
/custom/bar
, theresource
param will be['custom', 'bar']
So, one possible way is
resource
is string, compare withresource.name
andresource.route
resource
is array, splice the strings together (['custom', 'bar']-> '/custom/bar'
), and compare withresource.route