thepassle / app-tools

125 stars 8 forks source link

Fixes #9, external nav and nav to custom protocols #10

Closed JudahGabriel closed 1 year ago

JudahGabriel commented 1 year ago

Navigating to an external link (e.g. https://google.com) previously wouldn't actually navigate to that external link; it would try to match the fallback and navigate to that.

Additionally, navigating to a custom protocol (e.g. x-github-client://...) would throw an error as we tried to pushState() for different origins with the error,

Uncaught (in promise) DOMException: Failed to execute 'pushState' on 'History': A history state object with URL 'http://...' cannot be created in a document with origin 'http://.../' and URL 'http://...'. at Router.navigate (http://localhost:5173/node_modules/.vite/deps/@thepassle_app-tools_router__js.js?v=833e0bfe:186:20)

This PR is a small change: if we try to navigate to a different host, we set window.location.href to the desired link.

thepassle commented 1 year ago

Thinking more on this, it might make more sense to add this logic in between here: https://github.com/thepassle/app-tools/blob/53784beeae2ab311f6355280fe5c0a93de138d1c/router/index.js#L126-L129

JudahGabriel commented 1 year ago

Makes sense. I wondered if there was a better way to handle this.

I'll update the PR.

JudahGabriel commented 1 year ago

I've updated the PR, moving the check to the anchor click handler like you suggested.

thepassle commented 1 year ago

Thanks for the contribution!