question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Named routes and URL generation

See original GitHub issue

Hey

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:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
daviestarcommented, May 28, 2016

Thanks! Very small and elegant solution!

1reaction
krasimircommented, May 26, 2016

Nice idea and definitely possible. I’ll try implementing it during the weekend.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found