kiliman / remix-flat-routes

Remix package to define routes using the flat-routes convention
MIT License
640 stars 22 forks source link

Unable to add to custom routes with `defineRoutes` #75

Closed varndellwagglebee closed 9 months ago

varndellwagglebee commented 9 months ago

I'm using flat-folders and need to include two routes that are not in any folder.

example of what I currently have: routes(defineRoutes) { defineRoutes((route) => { route("/load/", "util/loaders/proxyGetLoader.tsx"); // simple get loader with auth returning json body route("/raw/", "util/loaders/proxyRawLoader.tsx"); // basic fetch with auth useful for images and downloads }) },

I'm unable to add the two routes I have above. I'm gettin defineRoutes is not a function

routes: async (defineRoutes) => { return flatRoutes("routes", defineRoutes((route) => { route("/load/", "util/loaders/proxyGetLoader.tsx"); // simple get loader with auth returning json body route("/raw/", "util/loaders/proxyRawLoader.tsx"); // basic fetch with auth useful for images and downloads })); },

kiliman commented 9 months ago

The defineRoutes param in remix-flat-routes is provided to the flatRotues function so the internals will work. It's not meant to be used like the current routes config.

Instead, call flatRoutes first, then you can use defineRoutes to create your custom routes and merge them.

module.exports = {
  ignoredRouteFiles: ['**/*'],
  routes: async defineRoutes => {
    const routes = flatRoutes('routes', defineRoutes)
    const customRoutes = defineRoutes(route => {
      route("/load/*", "util/loaders/proxyGetLoader.tsx"); // simple get loader with auth returning json body
      route("/raw/*", "util/loaders/proxyRawLoader.tsx"); // basic fetch with auth useful for images and downloads
    })
    return {...routes, ...customRoutes}
  },
}
varndellwagglebee commented 9 months ago

Ah, Thank you.

Annette Findley

Email: @.> @.

6531 Britannic Place

Frederick, MD 21703

From: Michael Carter @.> Sent: Monday, October 2, 2023 1:04 PM To: kiliman/remix-flat-routes @.> Cc: Annette Findley @.>; Author @.> Subject: Re: [kiliman/remix-flat-routes] Unable to add to routes (Issue #75)

The defineRoutes param in remix-flat-routes is provided to the flatRotues function so the internals will work. It's not meant to be used like the current routes config.

Instead, call flatRoutes first, then you can use defineRoutes to create your custom routes and merge them.

module.exports = { ignoredRouteFiles: ['*/'], routes: async defineRoutes => { const routes = flatRoutes('routes', defineRoutes) const customRoutes = defineRoutes(route => { route("/load/", "util/loaders/proxyGetLoader.tsx"); // simple get loader with auth returning json body route("/raw/", "util/loaders/proxyRawLoader.tsx"); // basic fetch with auth useful for images and downloads }) return {...routes, ...customRoutes} }, }

— Reply to this email directly, view it on GitHub https://github.com/kiliman/remix-flat-routes/issues/75#issuecomment-1743417709 , or unsubscribe https://github.com/notifications/unsubscribe-auth/A4AH6UDAKWBNDJI75I6PRHTX5LXYXAVCNFSM6AAAAAA5PVTLDSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONBTGQYTONZQHE . You are receiving this because you authored the thread. https://github.com/notifications/beacon/A4AH6UEXHHMOKLKHNVVH6QLX5LXYXA5CNFSM6AAAAAA5PVTLDSWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTH5JYW2.gif Message ID: @. @.> >