-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switching from HashRouter to BrowserRouter. This will switch urls from like https://near.social/#/mob.near/widget/Welcome to https://near.social/mob.near/widget/Welcome and automatically redirect.
- Loading branch information
Evgeny Kuzyakov
authored
Jul 28, 2023
1 parent
db725d8
commit 5ff6b26
Showing
11 changed files
with
57 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
# production | ||
/build | ||
/dist | ||
|
||
# misc | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useHistory } from "react-router-dom"; | ||
import React, { useCallback, useEffect } from "react"; | ||
|
||
export function useHashRouterLegacy() { | ||
const history = useHistory(); | ||
|
||
const onHashChange = useCallback( | ||
(event) => { | ||
let url = event.newURL.split("#").pop() ?? "/"; | ||
|
||
if (url[0] === "/") { | ||
history && history.replace(url); | ||
} | ||
}, | ||
[history] | ||
); | ||
|
||
useEffect(() => { | ||
window.addEventListener("hashchange", onHashChange); | ||
|
||
return () => { | ||
window.removeEventListener("hashchange", onHashChange); | ||
}; | ||
}, [onHashChange]); | ||
|
||
useEffect(() => { | ||
if (!history) { | ||
return; | ||
} | ||
const currentUrl = window.location.href; | ||
|
||
if (currentUrl.includes("#")) { | ||
const path = currentUrl.split("#")[1]; | ||
history.replace(path); | ||
} | ||
}, [history]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters