routegen
routegen copied to clipboard
Raising exceptions for generation of invalid routes
Hi, Love the idea of the library.
I've been trying it out and ran in to an interesting use case I wanted to see if you'd except a pull request to address.
assume a normal route setup something like below:
import routeGen from 'routegen';
const routes = routeGen({ baseUrl: '/',});
routes.set('dashboard', 'home');
routes.set('profile', 'profile');
I believe a call to r.generate('route_that_doesnt_exist')
should throw an exception - otherwise what's the point of strongly typing your routes if you don't know when one is incorrectly typed.
alternatively is the intent of the library to leave that up to the consumer to instead use constants or similar?
AKA
import routeGen from 'routegen';
const routes = routeGen({ baseUrl: '/',});
export const DASHBOARD = 'DASHBOARD';
export const PROFILE = 'PROFILE';
routes.set(DASHBOARD, 'home');
routes.set(PROFILE, 'profile');
Thank you!
I actually was thinking of this myself! I'll have a look at your PR, thanks!