Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sharing routeType.ts between pages question #106

Open
smndtrl opened this issue Sep 30, 2024 · 1 comment
Open

sharing routeType.ts between pages question #106

smndtrl opened this issue Sep 30, 2024 · 1 comment

Comments

@smndtrl
Copy link

smndtrl commented Sep 30, 2024

What is the correct approach to share route types between pages that share a common dynamic path? All my paths are prefix with tenantId and spaceId and I think it would make sense to to import { Route, type RouteType } from "../routeType"; for the different pages. The resulting typedefs look like the following when I don't put a routeType.ts into each and every single directory. Did I misunderstand how to properly use it?

For now I used symlinks instead of creating duplicates of the routeType.ts in the [spaceId] directory to not make the routes StaticRoute

  interface DynamicRouter {
    "/tenant/[tenantId]/space/[spaceId]": InferRoute<import("./app/(main)/(ui)/(error)/tenant/[tenantId]/space/[spaceId]/routeType").RouteType>;
  }

  interface StaticRouter {
    "/tenant/[tenantId]/space/[spaceId]/connections": StaticRoute;
    "/tenant/[tenantId]/space/[spaceId]/environment": StaticRoute;
    "/tenant/[tenantId]/space/[spaceId]/secrets": StaticRoute;
    "/tenant/[tenantId]/space/[spaceId]/settings": StaticRoute;
    "/tenant/[tenantId]/space/[spaceId]/users": StaticRoute;
  }
@ethanniser
Copy link
Owner

Sorry for the the late response,

I think you should probably still aim to have a routeType.ts for every route, just like you have a page.tsx for every route. You can define the schema in one place and import it in each file.

I see how its a bit repitive but im not sure symlinking is a superior solution, but let me know how things go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants