0

Currently I have a number of routes that follow formulas like so:

items/:item?

Is there a library that will allow me to do something like so:

generateUrl('items/:item?', { item : '1' }) = 'items/1'

1 Answer 1

1

I have found an answer, the package react-router contains a function here that does the job: https://github.com/ReactTraining/react-router/blob/master/packages/react-router/modules/generatePath.js#L23

So to generate my own routes I have to do the following:

import { generatePath } from "react-router"; generatePath('/items/:item?', { item: itemID });

Make sure you also install the path-to-regexp module.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.