-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Defining multiple routes with same route module #1898
Comments
This is something I'd like as well, the issue currently is we derive the route ID base on the file-path of the module, meaning the same module can't be shared for multiple route definitions. One thing I've considered is allowing another param to the |
I had somewhat similar issue while working on https://devtools.tech. I wanted to show the same file/component on two different routes. As @jacob-ebey mentioned the route ID is based on file path so you cannot include the same file twice. One solution I could think was abstract out the contents into a third component and import it into two different routes. // Component.js
...
export const links;
export const meta;
export default Component; // route /blog
import Component, { links as importedLinks, meta as importedMeta } from './Component';
export const links = importedLinks;
export const meta = importedMeta;
// we can directly export the component or wrap it if we want to pass or do anything extra.
export default Component; // route /resource
import Component, { links as importedLinks, meta as importedMeta } from './Component';
export const links = importedLinks;
export const meta = importedMeta;
// we can directly export the component or wrap it if we want to pass or do anything extra.
export default Component; I even tried defining a route in the routes folder like |
@jacob-ebey can't the key be the path you defined in the route() method? I don't know the underlying stack so I have absolutely no idea if that would cause any issues :D |
Paths will not work. Nested, layout, etc routes all can have the same path. |
Yeah, just noticed when running the tests, an optional user specified key in the options sounds like great way to solve this. Is this worth a PR from me? |
@gijsroge if you'd like to explore this and do a PR I'll follow up. If you are in the discord ping me there if you have any Q's. |
@jacob-ebey sorry I can't seem to find the time, also admitting I struggled with figuring this out. |
Perhaps the key can be |
following this as I have the same issue here |
One use-case for this that I see as being really valuable is translated urls. It's mentioned in this discussion, but to summarise: Having code located in the repo at en-US : path = /about Currently the way I've found that could support this is as part of a pre-build step. Before running |
I played around with the ability to add a |
@kiliman any reason why you are not attempting a PR for this rather than a third party package? |
I like to test out ideas first to see what works before trying to change the core. See my https://github.com/kiliman/remix-flat-routes
|
I think there also should be an option to pass params to route modules that will be available in <Routes>
<Route path="en" element={<Lang lang="en" />}/>
<Route path="es" element={<Lang lang="es" />}/>
<Route path="fr" element={<Lang lang="fr" />}/>
</Routes> |
Hi guys, I created a PR (#3970) trying to fix this problem, if someone could take a look ;) My ideia it's to pass a optional route ID when we have a multiple route conflict, something like this: module.exports = {
appDirectory: "app",
assetsBuildDirectory: "public/build",
devServerPort: 8002,
publicPath: "/build/",
serverBuildDirectory: "build",
ignoredRouteFiles: [".*"],
routes(defineRoutes) {
return defineRoutes(route => {
route("/user/:id", "routes/index.tsx", { id: "user-by-id" });
route("/user", "routes/index.tsx");
});
}
}; |
This is merged to dev and should be released in 1.9.0 next week or so 👍 |
What version of Remix are you using?
1.1.3
Steps to Reproduce
As explained in react router v6 https://reactrouter.com/docs/en/v6/faq#what-happened-to-regexp-routes-paths to create optional parameters you can define multiple paths with the same route module file.
But this doesn't work in Remix. The last defined route overrides the previous one.
run
npx create-remix@latest
remix.config.js
Expected Behavior
Both
user/:id
&user/
should renderroutes/index.tsx
Actual Behavior
only
user/
resolves,user/:id
returns a 404.The text was updated successfully, but these errors were encountered: