preactjs/wmr

preact-iso useLocation missing hash

dudo opened this issue · 2 comments

dudo commented

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?

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

Thank you for the clarification. Vanilla it is!