rmariuzzo / ruty

📦 Ruty is a simple URL route builder, that support typing route params and queries string with TypeScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feature request: get the original path from a built route

guesant opened this issue · comments

Let's suppose we have

import { Ruty } from 'ruty'

const { route } = Ruty.configure({
  prefix: '/:language'
})

const routes = {
  userById: route('/user/:id?created&sort').build(),
}

routes.userById({ id: 123 })
// '/user/123'

There is a way to get something like this?

routes.userById.path()
// /:language/user/:id

Or

routes.userById.path({includeParams: true}) // or just send `true` to get the original route
// /:language/user/:id/created&sort

Thank you for doing this package, I'll use it a lot.


Edit: or maybe this syntax

routes.userById.path({params: true}) // to get all the original params
routes.userById.path({params: { created: true, sort: false  }}) // to get `/user/:id?created`

hmm... it already does

ruty/src/route.test.ts

Lines 28 to 32 in cc395b1

it('should generate a route equal to the given path with params during building', () => {
const path = '/this/is/a/path/:param'
const routeInstance = route(path).build()
expect(routeInstance()).toBe(path)
})

Does that help you?

Yes. Thank you!