New version of JsRoutes doesn't try to guess your javascript environment module system because JS has generated a ton of legacy module systems in the past. ESM+Webpacker upgrade is recommended.
However, if you don't want to follow that pass, specify module_type
configuration option instead based on module system available in your JS environment.
Here are supported values:
- CJS
- UMD
- AMD
- ESM
- nil
If you don't want to use any JS module system and make routes available via a global variable, specify nil
as a module_type
and use namespace
option:
JsRoutes.setup do |config|
config.module_type = nil
config.namespace = "Routes"
end
New version of js-routes generates function comment in the JSDoc format. If you have any problems with that, you can disable it like this:
JsRoutes.setup do |config|
config.documentation = false
end
In case you are using required_params
property, it is now renamed and converted to a method:
// Old style
Routes.post_path.required_params // => ['id']
// New style
Routes.post_path.requiredParams() // => ['id']
ParameterMissing
is renamed to ParametersMissing
error and now list all missing parameters instead of just first encountered in its message. Missing parameters are now available via ParametersMissing#keys
property.
try {
return Routes.inbox_path();
} catch(error) {
if (error.name === 'ParametersMissing') {
console.warn(`Missing route keys ${error.keys.join(', ')}. Ignoring.`);
return "#";
} else {
throw error;
}
}