diff --git a/dist/tipagemRotas.d.ts b/dist/tipagemRotas.d.ts index cc6c976..0267412 100644 --- a/dist/tipagemRotas.d.ts +++ b/dist/tipagemRotas.d.ts @@ -31,7 +31,7 @@ export declare class TipagemRotas { ** "http://localhost:3000/caminho?q=query" */ - endereco(query: T) { + endereco(query: T, usarComoHash?: boolean) { const url = new URL( typeof window !== "undefined" ? window.location.href : "http://localhost", ) @@ -61,6 +61,12 @@ export class TipagemRotas { for (const [key, value] of queryKeys) { url.searchParams.set(String(key), value) } + + if (usarComoHash) { + url.hash = `#${url.search}` + url.search = "" + } + return url.href } @@ -85,6 +91,16 @@ export class TipagemRotas { ) const query = url.searchParams const queryObj = Object.fromEntries(query.entries()) + + // pegar hash + const hash = url.hash + if (hash) { + const hashObj = Object.fromEntries( + new URLSearchParams(hash.slice(1)).entries(), + ) + return { ...queryObj, ...hashObj } as T + } + return queryObj as T } }