Skip to content

Instantly share code, notes, and snippets.

@Weiyuan-Lane
Created August 11, 2019 12:44
Show Gist options
  • Save Weiyuan-Lane/2db0050d18a0d58c6962fc9df3d81e8e to your computer and use it in GitHub Desktop.
Save Weiyuan-Lane/2db0050d18a0d58c6962fc9df3d81e8e to your computer and use it in GitHub Desktop.
Wrapper for 'next/link' to introduce a base path
@dkarski
Copy link

dkarski commented Nov 5, 2019

Weiyuan Liu, thanks for your article. I came up with a suggestion while reading yours.

In my opinion, concatenate with / or without isn't readable. What do you think about setting the initial finalHref variable with basePath?

@Weiyuan-Lane
Copy link
Author

Hey dkarski!

I believe that both methodology would read the same, since the conditional check has to be introduced either way.

But I could have removed any trailing / from basePath and remove any initial / character from href, and do the following:

finalHref = `${basePath}/${href}`

No conditional checks. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment