3

I have reviewed some similar posts but unfortunately I am unable to get this right...

I have a switch statement that is providing a MD file depending on the URL path. Each path has many subpaths, for example /notebook/users/id and I would like to always match based on /notebook. I have attempted a few regex patterns but I am unable to successfully add the wildcard:

switch (location.href) {
        case `${URLZ}/${/^notebook.*/}`:
            return <Markdown value={data.notebook} />;

Thanks!

TecDvr
  • 33
  • 4

1 Answers1

1

If you're sure no other URLs contain '/notebook' beside the ones that should return <Markdown /> then refactor your switch statement to take true and do the check on your cases:

You can use String.includes to check if the location.href contains a '/notebook'

switch (true) {
  case location.href.includes('notebook'):
    return <Markdown value={data.notebook} />;

fortunee
  • 3,852
  • 2
  • 17
  • 29