routegen icon indicating copy to clipboard operation
routegen copied to clipboard

Raising exceptions for generation of invalid routes

Open JeremiahChurch opened this issue 5 years ago • 1 comments

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!

JeremiahChurch avatar Sep 10 '19 17:09 JeremiahChurch

I actually was thinking of this myself! I'll have a look at your PR, thanks!

drewjbartlett avatar Nov 07 '19 15:11 drewjbartlett