Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raising exceptions for generation of invalid routes #7

Open
JeremiahChurch opened this issue Sep 10, 2019 · 1 comment
Open

Raising exceptions for generation of invalid routes #7

JeremiahChurch opened this issue Sep 10, 2019 · 1 comment

Comments

@JeremiahChurch
Copy link

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!

@drewjbartlett
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants