Introduction
A simple URL generator in Javascript.
Installation
To install the stable version:
npm install --save url-routes-generator
This assumes you are using npm as your package manager.
Usage
First, register your routes:
; const Routes = params params params params params;
Then, you can call the Routes object to generate a valid URL.
Generate a route
Printing routes:
console; // /console; // /aboutconsole; // /invoices/23console; // /invoices/23/sendto/hello@example.comconsole
Example usage with react-router:
<Link to=Routes>About us</Link><Link to=Routes>Invoice</Link><Redirect to=Routes/>
Get the route pattern
If you are using react-router, you need to place the route pattern (/invoices/:id
) in the route definition. To get the route pattern, call the route with no params.
Example:
<Switch> <Route exact path=Routes component=Dashboard/> <Route path=Routes component=Invoice/></Switch>
Typescript
Type declarations are included in the package.
License
Open-sourced software licensed under the MIT license