Named routes and URL generation
See original GitHub issueHey
I love this router and have used it on a lot of small projects with no issues, thanks! I’m now scoping a larger project, and there’s one thing stopping me from using it there (well two related things).
Some example routes:
const trip = new TripController();
router.on({
'/trip/:tripId/edit': trip.edit,
'/trip/create': trip.create,
'/trip/:tripId': trip.show,
'/trip': trip.index
});
An example for a named route API (using Laravel 5.2 API as inspiration):
const trip = new TripController();
router.on({
'/trip/:tripId/edit': {as: 'trip.edit', uses: trip.edit},
'/trip/create': {as: 'trip.create', uses: trip.create},
'/trip/:tripId': {as: 'trip.show', uses: trip.show},
'/trip': {as: 'trip.index', uses: trip.index}
});
Then using the custom names, we don’t need to hardcode URLs in th views:
<a href="{{ router.generate('trip.show', {tripId: 6}) }}">...</a>
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
URL Generation - The PHP Framework For Web Artisans
Laravel allows you to easily create "signed" URLs to named routes. These URLs have a "signature" hash appended to the query string which...
Read more >Generate URLs to Named Routes in Laravel - Dev Notes
Named routes in Laravel allow you to easily generate specific URLs. Referring to the named route throughout your project makes the codebase ...
Read more >Navigate with named routes - Flutter documentation
The solution is to define a named route, and use the named route for navigation. To work with named routes, use the Navigator....
Read more >Laravel 5: Generating URLs to Named Routes With route - Stillat
The route helper function can be used to generate URLs to a given named route. The route function defines four parameters, but only...
Read more >Named Routes in Laravel - Javatpoint
Named routes is an important feature in the Laravel framework. It allows you to refer to the routes when generating URLs or redirects...
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 FreeTop 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
Top GitHub Comments
Thanks! Very small and elegant solution!
Nice idea and definitely possible. I’ll try implementing it during the weekend.