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

Supported basePath for to prop when passed as string. Resolving acces… #227

Merged

Conversation

tpuric
Copy link
Collaborator

@tpuric tpuric commented Mar 4, 2024

Resolves #225

Supported basePath for to prop when passed as string.
Resolves accessibility issues for new tabs/window interactions.

Test added:

  • should support the to prop with basePath
  • should push history with correct link given basePath

basePath

generateLocationFromPath(route.path, routeAttributes)
)) ||
''
: `${routeAttributes.basePath}${to}`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah so this is obviously hacked in, looking for input on a better way of handling this.

Essentially the problem here is that linkDestination is used for both router actions and anchor props (href). Router actions automatically prepends basePath whilst anchor props do not, hence why we are in the current state.

This example splits the logic so they are handled separately. The approach is very naive, please provide suggestions. Alternatively, we could look at converting string typed to's to routes?

Anyways, looking for feedback, thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already calculate the href above, don't need to recalculate everything again. We just need to understand if we need to add basepath.

const staticBasePath = href == null && typeof to === 'string' ? routeAttributes.basePath : ''
// ...
validLinkType,
  {
  ...rest,
  href: staticBasePath + linkDestination,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've applied these changes, thanks @albertogasparin

@tpuric tpuric force-pushed the support-basePath-for-string-typed-to branch from e001ece to 1dbb843 Compare March 4, 2024 23:26
@pancaspe87 pancaspe87 merged commit 13a946f into atlassian-labs:master Mar 4, 2024
3 checks passed
@tpuric tpuric deleted the support-basePath-for-string-typed-to branch March 4, 2024 23:42
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

Successfully merging this pull request may close these issues.

Routing for new tabs or windows are not recognising basePath
3 participants