@izzyjs/route
Version:
Use your AdonisJs routes in your Inertia.js application
26 lines (25 loc) • 706 B
JavaScript
/**
* @izzyjs/route
*
* (c) IzzyJs - 2024
* For the full license information, please view the LICENSE file that was distributed with this source code.
*/
export function serializeRoute(route, domain = 'root') {
const methods = route.methods.filter((method) => method !== 'HEAD').at(0);
const params = route.pattern.match(/:\w+/g)?.map((param) => param.slice(1));
if (params) {
return {
name: route.name,
path: route.pattern,
method: methods.toLowerCase(),
params,
domain,
};
}
return {
name: route.name,
path: route.pattern,
method: methods.toLowerCase(),
domain,
};
}