typesafe-routes icon indicating copy to clipboard operation
typesafe-routes copied to clipboard

Proper way to compose routes

Open Xample opened this issue 10 months ago • 1 comments

Hello, in our project we do organise feature folders with all its dependencies so that we can share a feature folder between projects. Something like that:

import { createRoutes, int, RouteNodeMap } from 'typesafe-routes';

// feature/user.route.ts folder
export const Users = {
    list: {
        path: ['list'],
    },
    detail: {
        path: ['detail', int('uid')],
  },
} satisfies RouteNodeMap;

// feature/cart.route.ts folder
export const Cart = {
  detail: {
    path: ['detail'],
  },
} satisfies RouteNodeMap;


// app.route.ts folder
export const routes = createRoutes({
    user: {
        path: ['user'],
        children: Users,
    },
    cart: {
      path: ['cart'],
      children: Cart,
  },
});

I expected to be able to put a routeContext into another routeContext but it seems no to be possible (and there is no toRouteNodeMap converter (?)) so is there another way to compose routes or we are doing it the right way ?

Xample avatar Apr 15 '24 08:04 Xample