Skip to content
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

Url generator #83

Open
adeys opened this issue Oct 17, 2019 · 0 comments
Open

Url generator #83

adeys opened this issue Oct 17, 2019 · 0 comments

Comments

@adeys
Copy link

adeys commented Oct 17, 2019

Hello everyone. That's more a feature request than an issue.
For the implementation, I think we can add support for named routes first as it'll help make certain routes unique. We could then upon these names have an url generator which would generate the urls for these names routes provided custom parameters.

As for the named routes it could be something like this:

router.get(path, middleware1, [middleware2], {name: 'route.name'});

In this case the route configuration object which hold the route name is the last parameter and is then optional. There may be other options which could be added later.

For the url generation we could have something like:

router.get('post/:year/:month/:slug', handler, {name: 'post.show'});

let url = router.pathFor('post.show', {year: 2019, month: 'oct', slug: 'dummy-post-title'});
// url : 'post/2019/oct/dummy-post-title'

let url = router.pathFor('post.show', {year: 2019, month: 'oct', slug: 'dummy-post-title', order: 'asc'});
// url : 'post/2019/oct/dummy-post-title?order=asc'

Or there could be by example a separate url generator object/class which will receive the router as constructor argument and implement the pathFor method.

I hope this is clear enough.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants