Skip to content

Redirect callback example in docs - reversed logic in ternary #931

Discussion options

You must be logged in to vote

Hi there! The docs says:

By default only URLs on the same URL as the site are allowed, you can use the redirect callback to customise that behaviour.

Meaning that by default, only absolute URLs are handled, that also match (starts with) the base url , all others will go to the baeUrl or the homepage.

To support relative urls, this is what I did in our app:

async redirect(url, baseUrl) {
  if(url.startsWith(baseUrl) {
    return url
  }

  return new URL(url, baseUrl).toString()
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by balazsorban44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #931 on December 08, 2020 20:35.