fix(elements): Use window.location to navigate for absolute URLs#3934
fix(elements): Use window.location to navigate for absolute URLs#3934
Conversation
🦋 Changeset detectedLatest commit: 8828f25 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| push: (path: string) => { | ||
| if (isAbsoluteUrl(path)) { | ||
| window.location.href = path; | ||
| } else { | ||
| router.push(path); | ||
| } | ||
| }, |
There was a problem hiding this comment.
Maybe i am missing some context here, but is this different from this windowNavigate within clerk-js
There was a problem hiding this comment.
Also I believe the nextjs router's push will respect the absolute path and it will perform the navigation.
There was a problem hiding this comment.
I totally thought the same thing about push, but in my testing it did not (at least with cross-origin domains, not sure about same-origin). I know the <Link> component handles cross-origin absolute URLs though, so I think that's where I got confused.
We can definitely bring windowNavigate over into Elements for the additional functionality. Good call!
There was a problem hiding this comment.
I tested with App router router.push('https://google.com') and seems to work. i've not tested with absolute url and same origin tho.
If you see something different, it may be an inconsistency across nextjs versions. so having the above logic will be required in that case.
There was a problem hiding this comment.
You're absolutely right. In Elements we have two routers, ClerkRouter and FrameworkRouter, which ClerkRouter wraps. I was calling ClerkRouter.push(absoluteUrl), which doesn't work because it transforms the URL into /?redirect_url=absoluteUrl, and then calls FrameworkRouter.push("/?redirect_url=absoluteUrl"), which doesn't work. Calling FrameworkRouter.push(absoluteUrl) totally works as expected.
I'll close this PR in favor of a new one that reworks ClerkRouter to prevent the transformation of absolute URLs.
|
Closing in favor of #3947 |
Description
Adds support for navigating to absolute URLs via
context.router.push. This allowsredirect_urlto be an absolute URL.Checklist
npm testruns as expected.npm run buildruns as expected.Type of change