How can I use Ziggy with React and Inertia ?
See original GitHub issueHow can I call in a React component the JavaScript route
function generated by the Ziggy’s @route
directive ?
The route
function is generated at runtime so it’s impossible to import it beforehand in the react component and therefore, Laravel Mix throws an error and can’t compile the project.
My stack is Laravel 8, Inertia & React.
Thanks !
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
How to use Ziggy with React and Inertia - Stack Overflow
The ziggy route() function is defined globally so you can access it anywhere in your react component. – chuysbz. Sep 22, 2020 at...
Read more >Using Ziggy with Inertia Server-Side Rendering - Aaron Francis
The first thing we need to do is get all the routes into Ziggy. In a standard Laravel app this is done with...
Read more >09 - Using the ziggy library with InertiaJS for handling routes
Laravel 8 step by step guide | Bookmark app using React, Inertia Js and deployment to Linux · Getting Started With Laravel and...
Read more >What is @routes in app.blade.php [inertia-react app]?
I can see @routes directive in app.blade.php in my inertia-react app. ... @routes import all Laravel routes in order to use them in...
Read more >Routing - Inertia.js
With Inertia all routing is defined server-side. Meaning you don't need Vue Router or React Router. Simply create routes using your server-side framework...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can import the
route()
function either from Ziggy’s vendor directory, with something likeadded to your Webpack config, or by installing the
ziggy-js
npm package.Ziggy provides an artisan command,
php artisan ziggy:generate
, that will generate the object with all of your route information and put it either atresources/assets/js/ziggy.js
or at the path you pass it.After doing those two things, you should be able to just
and use
route()
normally.Take a look at the Artisan Command section in the readme too.
I’m going to close this but let me know if that works and if you have any other questions!
@caturandi-labs https://vitejs.dev/config/#resolve-alias