preactjs / wmr

👩‍🚀 The tiny all-in-one development tool for modern web apps.
https://wmr.dev/
MIT License
4.92k stars 109 forks source link

preact-iso useLocation missing hash #939

Closed dudo closed 2 years ago

dudo commented 2 years ago

Describe the bug

I'm trying to get the url fragment component out of a callback (anything after a #). As it stands, when a # is in the url, everything shows as null

image

To Reproduce

import { useLocation } from "preact-iso";

const { url, path, query } = useLocation();

Expected behavior

Should we be exposing a hash key from useLocation? Is there another way to grab that?

developit commented 2 years ago

Hiya! Because preact-iso doesn't do anything with hashes (routing or otherwise), they're left for the browser to handle. This is done because we don't intercept anchor/hash links and don't re-execute your Routes when the hash changes.

If you want to parse those parameters from the hash in your screenshot, you can do this:

const authCallbackParams = new URLSearchParams(location.hash.slice(1))

console.log(params.get('access_token');
dudo commented 2 years ago

Thank you for the clarification. Vanilla it is!