@izzyjs/route
Version:
Use your AdonisJs routes in your Inertia.js application
25 lines (24 loc) • 880 B
JavaScript
const tag = {
block: false,
tagName: 'routes',
seekable: true,
compile: (_, buffer, token) => {
buffer.writeExpression(`out += state.izzy(state.cspNonce, state.request.url())`, token.filename, token.loc.start.line);
},
};
export const edgePluginIzzy = (routes, config) => {
return (edge) => {
edge.global('izzy', (cspNonce, url) => {
const configScript = config?.baseUrl ? `,\n\t\tconfig: { baseUrl: "${config.baseUrl}" }` : '';
return [
`<script${cspNonce ? ` nonce="${cspNonce}"` : ''}>`,
`\t(globalThis || window).__izzy_route__ = {`,
`\t\troutes: ${JSON.stringify(routes)},`,
`\t\tcurrent: "${url}"${configScript}`,
`\t};`,
'</script>',
].join('\n');
});
edge.registerTag(tag);
};
};