Isomorphic Hooks
useUrlBuilder
Build URLs to routes of the application.
Client / Server
Usage
Build the URL for a controller action.
import { useUrlBuilder } from '@microeinhundert/radonis'
const urlBuilder = useUrlBuilder()
const url = urlBuilder.make$('UsersController.index') // => `/users`
Build the URL with params.
import { useUrlBuilder } from '@microeinhundert/radonis'
const urlBuilder = useUrlBuilder()
const url = urlBuilder.make$(
'UsersController.show',
{
params: { id: 1 },
},
) // => `/users/1`
Build the URL with query params.
import { useUrlBuilder } from '@microeinhundert/radonis'
const urlBuilder = useUrlBuilder()
const url = urlBuilder.make$(
'TechController.index',
{
queryParams: {
cool: ['adonis', 'react'],
},
},
) // => `/tech?cool=adonis,react
There is also a standalone URL builder exported as UrlBuilder
from @microeinhundert/radonis
with the same API as the useUrlBuilder
hook.