If you're manually setting up Inertia in your Laravel project (without using a pre-configured boilerplate), you might run into issues with accessing Laravel named routes in JavaScript. Here’s how to make sure your routes work properly:
composer require tightenco/ziggy
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- Include Laravel routes in JavaScript -->
@routes
@viteReactRefresh
@vite('resources/js/app.jsx')
@inertiaHead
</head>
<body>
@inertia
</body>
</html>
Common issue If you see that @routes isn’t recognized and instead renders as plain text, try using it with parentheses like this:
@routes()