Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No back button #9

Open
quertc opened this issue Jul 30, 2024 · 3 comments
Open

No back button #9

quertc opened this issue Jul 30, 2024 · 3 comments

Comments

@quertc
Copy link

quertc commented Jul 30, 2024

In the latest version with App Router there is no back button after routing. In previous versions with Pages Router (for example, 39c4e4f) this button exists and works correctly. This also works for https://github.com/Telegram-Mini-Apps/reactjs-template.

image

@heyqbnk
Copy link
Member

heyqbnk commented Aug 22, 2024

Does it work fine for you now?

@quertc
Copy link
Author

quertc commented Sep 24, 2024

Does it work fine for you now?

No.

@musme
Copy link

musme commented Sep 24, 2024

It`s maybe a wrong way but I added the BackButton this way:

src\components\Root\Root.tsx

import {initBackButton} from "@telegram-apps/sdk-react";
import { usePathname, useRouter } from "next/navigation";

...

function App(props: PropsWithChildren) {
  const [backbutton] = initBackButton();
  const { back } = useRouter();
  const pathname = usePathname();
  
  const onBackClick = useCallback(() => {
    if (pathname !== "/") {
      back();
    }
  }, [back, pathname]);
  
  useEffect(() => {
    backbutton.on("click", onBackClick);
    return () => {
      backbutton.off("click", onBackClick);
    };
  }, [backbutton, onBackClick]);
  
  useEffect(() => {
    if (pathname !== "/") {
      backbutton.show();
    } else {
      backbutton.hide();
    }
  }, [backbutton, pathname])
  
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants