-
Notifications
You must be signed in to change notification settings - Fork 62
Add currentRoute function for route detection with TypeScript support #104
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
base: main
Are you sure you want to change the base?
Conversation
- Introduced `currentRoute` function in README with detailed usage examples, return types, and handling of route and query parameters. - Updated `wayfinder.ts` to include new type definitions for route arguments. - Enhanced `GenerateCommand.php` to support vendor route generation and improved route filtering. - Added `isVendorRoute` method in `Route.php` to identify vendor routes. - Updated web routes in `web.php` for testing current route functionality.
… definition generation
|
Watch this Laravel Podcast video TypeScript, Wayfinder, and Ranger with Joe Tannenbaum. According to it 'wayfinder', is front-end framework agnostic (not just for InertiaJS). I believe this feature is better suited to the Inertia library itself. I opened a discussion thread inertiajs/inertia#2564, where I suggest implementing the useRoute hook, which already includes this feature. Feel free to use it as a basis for opening a pull request there. |
|
Hey, thanks a lot for pointing this out, it's a really good angle. Let me explain why I believe putting that functionality in Wayfinder gives a better developer experience — especially for type safety and route suggestions.
For the current stage, I believe |
|
With Wayfinder I don't have to name my routes anymore. Could this PR do something like |
…er definitions and query parameters
|
Hey @yoeriboven you are absolutely right 👏 Some users still rely on named routes being passed from the backend to the frontend (for example, to highlight the active navigation tab or conditionally render components). In those cases, they can’t easily reference the controller or route definition directly through Wayfinder. So, to cover both use cases, I’ve added support for both approaches in currentRoute():
Example usage: import PostController from "@/actions/App/Http/Controllers/PostController";
import { show } from "@/actions/App/Http/Controllers/PostController";
// Using controller object
currentRoute(PostController.show(123));
currentRoute(PostController.show.url({ post: 123 }));
// Using imported method
currentRoute(show({ post: 123 }));
// With query parameters
currentRoute(PostController.show({ post: 123 }, { query: { q: "test" } }));
// Also works with Invokable controllers
currentRoute(InvokableController());Thanks again, @yoeriboven, for the great suggestion — this helped make the feature more flexible for everyone. 🙌 |
|
Hey @joetannenbaum @taylorotwell @timacdonald should i completely remove named route and keep only controller route definition approach for checking or should i keep current version which is named route + controller route definition approach because as i mention earlier
so what you think? |

Current Route Detection Feature for Laravel Wayfinder
Overview
This update brings a new
currentRoutefunction to Laravel Wayfinder, designed as a modern, TypeScript-friendly replacement for Ziggy'sroute().current(). It provides powerful route detection capabilities with full TypeScript support and intuitive APIs.Key Benefits
Core Features
Basic Route Detection
Controller RouteDefinition Approach
Use Wayfinder-generated controller methods directly:
Invokable Controllers
Direct Named Routes
Advanced Parameter Handling
Ziggy Migration
Before (Ziggy)
After (Wayfinder)
Real-World Use Cases
Navigation Components
Conditional Rendering
Form State Management
Technical Implementation
GenerateCommand.php
isVendorRoutemethod to identify vendor routes--with-vendor-routesflag for including vendor routesUpdated Route.php
isVendorRoutemethod to identify vendor routesNew Type Definitions
TypeScript Named Route Auto-Suggestion
When you use Wayfinder, TypeScript auto-suggestion for route names (
RouteName) is enabled by generating aroutes.tsfile in the same directory where yourwayfinder/index.tsfile is created. Thisroutes.tsfile is automatically generated alongsideindex.tsand contains:namedRoutes: An object with all available route names for auto-completion and type safety.isValidWildcardPattern: A utility to validate wildcard route patterns.checkQueryParams: A helper to check and match query parameters for routes.With this setup, we’ll always get the latest route name suggestions and helpful utilities right in our editor. That means you can quickly find, check, and match routes with confidence—no guesswork, no manual updates, and no type errors.
Update: 2025-10-21
post.*.showforcedSchemeandforcedRootin CurrentRouteService, becase it's not usedcurrentRoute()funtion and remove duplicate code