tatethurston / nextjs-routes

Type safe routing for Next.js
MIT License
580 stars 21 forks source link

Error: Dynamic href `/[store]` found in <Link> while using the `/app` router, this is not supported. #190

Closed ziggy6792 closed 2 months ago

ziggy6792 commented 3 months ago

Thanks a lot for this cool package! It seems dyanmic routes do not work though, maybe this is a new next thing?

Steps to reproduce

Check out this repo

pnpm package:build
cd examples/app
pnpm dev    
Screenshot 2024-08-15 at 3 45 09 PM

As a work around I created a utility function, but this is not ideal

import { format } from 'url';
import { type Route } from 'nextjs-routes';

export const routeToString = ({ query, pathname }: Route): Route => {
  // Replace dynamic segments in the pathname with corresponding query values
  let formattedPathname = pathname as string;

  for (const key in query) {
    const value = query[key];
    // If the key is an array, join its elements with '/'
    const replacedValue = Array.isArray(value) ? value.join('/') : value;
    // Replace the dynamic segment with the query value
    formattedPathname = formattedPathname.replace(`[${Array.isArray(value) ? '...' : ''}${key}]`, replacedValue!);
  }

  return format({ pathname: formattedPathname }) as unknown as Route;
};
tatethurston commented 3 months ago

Hey @ziggy6792 the app directory is not currently supported: https://github.com/tatethurston/nextjs-routes/issues/170

tatethurston commented 1 month ago

Now supported in 2.2.2