bradstiff / react-app-location

A package to avoid repetition with Routes and URLs, and reduce boilerplate with location param parsing in React Apps
MIT License
97 stars 8 forks source link

Can URL params be matched? #12

Open YM-KA opened 5 years ago

YM-KA commented 5 years ago

Can URL params be matched to a specific route?

I would like something like export const ManageAccountLocation = new Location('/auth/action') export const ManageAccountLocationLink = new Location('/auth/action?mode=:mode', {mode: str.required()})

for the below link to generate a unique route separate from /auth/action http://127.0.0.1:8080/auth/action?mode=resetPassword

carmouche commented 4 years ago

I think you could do something like

new Location(
        '/auth/action',
        {},
        {mode: Yup.str.required()}
    )

The second parameter that I left as an empty object is for "route params", and the 3rd one does query (URL) params which I believe is what you want :)

Location.ctor(path: string, pathParamDefs: ?schema, queryStringParamDefs: ?schema): Location