Reputation: 1527
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'
Upvotes: 0
Views: 24
Reputation: 1527
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.
Upvotes: 1