Skip to content

Url generator #83

@adeys

Description

@adeys

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions