mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2025-12-23 01:04:18 +01:00
30 lines
791 B
TypeScript
30 lines
791 B
TypeScript
import { useLocation, useNavigate } from "solid-start";
|
|
|
|
import { BackButton } from "~/components";
|
|
import { useI18n } from "~/i18n/context";
|
|
|
|
type StateWithPrevious = {
|
|
previous?: string;
|
|
};
|
|
|
|
export function BackPop() {
|
|
const i18n = useI18n();
|
|
const navigate = useNavigate();
|
|
const location = useLocation();
|
|
|
|
const state = location.state as StateWithPrevious;
|
|
|
|
// If there's no previous state want to just go back one level, basically ../
|
|
const newBackPath = location.pathname.split("/").slice(0, -1).join("/");
|
|
|
|
const backPath = () => (state?.previous ? state?.previous : newBackPath);
|
|
|
|
return (
|
|
<BackButton
|
|
title={i18n.t("common.back")}
|
|
onClick={() => navigate(backPath())}
|
|
showOnDesktop
|
|
/>
|
|
);
|
|
}
|