melhorias
This commit is contained in:
parent
7971b508c6
commit
de77a4c8b6
5 changed files with 31 additions and 5 deletions
12
dist/tipagemRotas.js
vendored
12
dist/tipagemRotas.js
vendored
|
|
@ -46,13 +46,17 @@ class TipagemRotas {
|
|||
** console.log(mCaminho.resolve({q:"query"}))
|
||||
** "http://localhost:3000/caminho?q=query"
|
||||
*/
|
||||
endereco(query) {
|
||||
endereco(query, usarComoHash) {
|
||||
const url = new URL(typeof window !== "undefined" ? window.location.href : "http://localhost");
|
||||
url.pathname = this.caminho;
|
||||
const queryKeys = typeof query == "object" && query ? Object.entries(query) : [[query, ""]];
|
||||
for (const [key, value] of queryKeys) {
|
||||
url.searchParams.set(String(key), value);
|
||||
}
|
||||
if (usarComoHash) {
|
||||
url.hash = `#${url.search}`;
|
||||
url.search = "";
|
||||
}
|
||||
return url.href;
|
||||
}
|
||||
/** Vai para a url
|
||||
|
|
@ -72,6 +76,12 @@ class TipagemRotas {
|
|||
const url = new URL(typeof window !== "undefined" ? window.location.href : "http://localhost");
|
||||
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 };
|
||||
}
|
||||
return queryObj;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue