Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useRoute() React hook #473

Merged
merged 5 commits into from
Sep 1, 2023
Merged

Add useRoute() React hook #473

merged 5 commits into from
Sep 1, 2023

Conversation

bakerkretzmar
Copy link
Collaborator

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.

@felipeva
Copy link

Is there a way you can use this with typescript?

@bakerkretzmar
Copy link
Collaborator Author

bakerkretzmar commented Oct 10, 2021

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

@deevus
Copy link

deevus commented Mar 7, 2022

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.

@bakerkretzmar bakerkretzmar self-assigned this May 6, 2022
@bakerkretzmar bakerkretzmar added this to the v2.0 milestone May 6, 2022
@bakerkretzmar bakerkretzmar marked this pull request as ready for review May 6, 2022 16:40
Copy link

@mro95 mro95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very simple solution :)

@CamKem
Copy link

CamKem commented Jul 18, 2023

Is there something similar for Vue?

@bakerkretzmar
Copy link
Collaborator Author

@bakerkretzmar bakerkretzmar merged commit f2b43c0 into main Sep 1, 2023
@bakerkretzmar bakerkretzmar deleted the jbk/use-route-hook branch September 1, 2023 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mention React usage in Readme
5 participants