Use adonis routes in the client
npm install @eidellev/adonis-stardust
Use your adonis named stardust in the client.
``shell
npm i @eidellev/adonis-stardust
node ace configure @eidellev/adonis-stardust
`
Add the Stardust middleware to start/kernel.ts:
`typescript`
Server.middleware.register([
() => import('@ioc:Adonis/Core/BodyParser'),
() => import('@ioc:EidelLev/Stardust/Middleware'),
]);
Create a named route in your stardust file:
`typescript`
Route.get('users/:id', () => {
...
}).as('users.show');
Add the @routes Edge tag to your main layout (before your application's JavaScript).
`blade`
@routes
@entryPointStyles('app')
@entryPolintScripts('app')
Stardust should be initialized as early as possible, e.g. in your application's entrypoint
`typescript
import { initRoutes } from '@eidellev/adonis-stardust/client';
initRoutes();
`
Now you can use the stardust helper to access your adonis routes:
`typescript
import { stardust } from '@eidellev/adonis-stardust/client';
stardust.route('users.show', { id: 1 }); // => /users/1
/**
* You can also pass path params as an array and they will populated
* according to their order:
*/
stardust.route('users.show', [1]); // => /users/1`
You can also pass query parameters like so:
`typescript/tasks?tags=work,personal
stardust.route('tasks.index', undefined, { qs: { tags: ['work', 'personal'] } });
//
``
`typescript``
stardust.current; // => 'tasks.index'
stardust.isCurrent('tasks.index'); // => true