typesafe-routes
typesafe-routes copied to clipboard
Proper way to compose routes
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 ?