ziggy icon indicating copy to clipboard operation
ziggy copied to clipboard

Add `useRoute()` React hook

Open bakerkretzmar opened this issue 3 years ago • 3 comments

Adds a useRoute() React hook. If the Ziggy config object is available globally, usage is as simple as:

import { useRoute } from 'ziggy-js';

export default () => {
    const route = useRoute();

    return (
        <a href={route('home')}>Home</a>
    );
};

Closes #327.

bakerkretzmar avatar Oct 08 '21 18:10 bakerkretzmar

Is there a way you can use this with typescript?

felipeva avatar Oct 10 '21 21:10 felipeva

@FelipeVa no idea 😅 if you can import JavaScript modules into TypeScript then I don't see why not.

bakerkretzmar avatar Oct 10 '21 21:10 bakerkretzmar

See here https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html

Since this package uses JSDoc it would be possible to generate definition files for the project.

deevus avatar Mar 07 '22 03:03 deevus

Is there something similar for Vue?

CamKem avatar Jul 18 '23 08:07 CamKem

@CamKem https://github.com/tighten/ziggy#vue

bakerkretzmar avatar Jul 18 '23 19:07 bakerkretzmar