Allow customizing the prefix for Dynamic Segments #4021
ianwremmel
started this conversation in
Proposals
Replies: 1 comment 1 reply
-
Here's a function that will let you choose any character as the param prefix. // remix.config.js
const {
defineConventionalRoutes,
} = require(https://github.com/remix-run/remix/tree/master/packages/remix-dev);
/**
* @type {import(https://github.com/remix-run/remix/tree/master/packages/remix-dev).AppConfig}
*/
module.exports = {
ignoredRouteFiles: ["**/.*"],
routes: () => updateParamPrefix("^"),
};
function updateParamPrefix(paramPrefix) {
const conventionalRoutes = defineConventionalRoutes("app", ["**/.*"]);
const fixPath = (path) => {
return path === paramPrefix
? "*" // handle catch-all
: path?.replaceAll(paramPrefix, ":");
};
return Object.fromEntries(
Object.entries(conventionalRoutes).map(([key, route]) => [
key,
{ ...route, path: fixPath(route.path) },
])
);
} https://gist.github.com/kiliman/9d238aebd0fce58de20878803615f729 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
While using
$
as the dynamic segment indicators seems to make sense (dollar sign being a common variable indicator), it really makes scripting difficult. I'm using Remix in a few different projects that are orchestrated by Makefiles and there's really no way to escape the$
.Would it be possible to allow providing an alternate character (or string) via
remix.config.js
?Beta Was this translation helpful? Give feedback.
All reactions