mirror of
https://github.com/p-stream/p-stream.git
synced 2026-05-10 00:01:04 +00:00
make router history a bit safer
This commit is contained in:
parent
cb5b46d7c9
commit
9aa6e4088a
1 changed files with 12 additions and 7 deletions
|
|
@ -19,6 +19,9 @@ export const useHistoryStore = create(
|
|||
registerRoute(route) {
|
||||
set((s) => {
|
||||
s.routes.push(route);
|
||||
if (s.routes.length > 50) {
|
||||
s.routes.shift();
|
||||
}
|
||||
});
|
||||
},
|
||||
})),
|
||||
|
|
@ -40,16 +43,18 @@ export function useLastNonPlayerLink() {
|
|||
const routes = useHistoryStore((s) => s.routes);
|
||||
const location = useLocation();
|
||||
const lastNonPlayerLink = useMemo(() => {
|
||||
const reversedRoutes = [...routes];
|
||||
reversedRoutes.reverse();
|
||||
const route = reversedRoutes.find(
|
||||
(v) =>
|
||||
for (let i = routes.length - 1; i >= 0; i -= 1) {
|
||||
const v = routes[i];
|
||||
if (
|
||||
!v.path.startsWith("/media") && // cannot be a player link
|
||||
location.pathname !== v.path && // cannot be current link
|
||||
!v.path.startsWith("/s/") && // cannot be a quick search link
|
||||
!v.path.startsWith("/onboarding"), // cannot be an onboarding link
|
||||
);
|
||||
return route?.path ?? "/";
|
||||
!v.path.startsWith("/onboarding") // cannot be an onboarding link
|
||||
) {
|
||||
return v.path;
|
||||
}
|
||||
}
|
||||
return "/";
|
||||
}, [routes, location]);
|
||||
return lastNonPlayerLink;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue