Skip to content

Duplicating route structures under a different path #9298

Closed Answered by renevds
renevds asked this question in Q&A
Discussion options

You must be logged in to vote

I ended up solving it using the following plugin in vite.config.ts:

Some config at the top of the file:

const routesToReplace = 'routes/pageA/modal'

const routesToReplaceWith = [
  'routes/pageB/modal',
  'routes/pageC/modal',
]

The remix plugin:

remix({
      ignoredRouteFiles: ['**/*'], // Make sure the default router is not used
      routes: async () => {
        // Call the default flat route generator
        const routes = flatRoutes('app', [], 'routes')

        // Duplicate the route to all the new routes
        for (const routeKey of Object.keys(routes)) {
          if (
            routeKey.startsWith(routesToReplace) &&
            routeKey !== routesToReplace
          ) {

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@renevds
Comment options

@kiliman
Comment options

@renevds
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by renevds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants