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

PolarisProvider handleClick not going through react router #306

Open
key88sf opened this issue Oct 16, 2024 · 0 comments
Open

PolarisProvider handleClick not going through react router #306

key88sf opened this issue Oct 16, 2024 · 0 comments

Comments

@key88sf
Copy link

key88sf commented Oct 16, 2024

Hi - I'm using the frontend react template as part of a Ruby/Rails app created with the Shopify App Template for Ruby (https://github.com/Shopify/shopify-app-template-ruby).

Problem:
All internal links which are added via Polaris components end up opening in a new tab, and do not use the proper shopify admin/app URL. Instead they open a URL with the backend server host name.

Example:

<Link url="/pagename">Click Me</Link>

Expected click behavior:

  • Same browser window
  • URL should be https://admin.shopify.com/store/my-store/apps/my-app/pagename

Actual click behavior:

  • New tab opened
  • URL is https://<backend server host name>/pagename

I think the bug is in the PolarisProvider.jsx. The change in this commit switched to using window.open for the click handler for internal links, which caused the new behavior. The old App Bridge v3 version (using navigate()) worked fine.

I believe the proper fix is to do this in PolarisProvider.jsx:

import {useNavigate} from "react-router-dom";
...
const navigate = useNavigate();
const handleClick = useCallback(() => navigate(url), [url]);
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

No branches or pull requests

1 participant