Template Literals 7 exercises

Only Allow Specified String Patterns

Here we have a function called goToRoute, where Route is currently unknown:

We want to make it so that only certain types of strings can be passed into goToRoute:

Loading exercise


0:00 In this exercise, we have a function called goToRoute. And goToRoute, what we're looking at here is we've got, we basically want to say this can only be certain type of strings that can be passed in to goToRoot. Currently, root is just unknown, so we know we need to change this unknown into something.

0:18 But what we want is to basically say any string that starts with a slash, we should allow it to be passed in to goToRoute, as in we can't have any HTTP stuff in here, and we can't have like users one here. So we want an absolute root, that's the only thing that we should be allowed to pass in. So you're gonna have to look here

0:38 for template literal types.

0:40 That's the way to solve this challenge.