Fix app deep linking when mount path set (#2137)

This commit is contained in:
Dawid 2022-07-05 12:53:47 +02:00 committed by GitHub
parent 1f179f8fbd
commit e924fb001c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,9 +1,11 @@
import { Actions, DispatchResponseEvent, Events } from "@saleor/app-bridge";
import { appPath } from "@saleor/apps/urls";
import { APP_MOUNT_URI } from "@saleor/config";
import useNavigator from "@saleor/hooks/useNavigator";
import React from "react";
import { useIntl } from "react-intl";
import { useLocation } from "react-router";
import urlJoin from "url-join";
import { useExternalApp } from "../ExternalAppContext";
@ -52,8 +54,10 @@ export const useAppActions = (
if (newContext) {
window.open(to);
} else if (appDeepUrlChange) {
const exactLocation = urlJoin(APP_MOUNT_URI, to);
// Change only url without reloading if we are in the same app
window.history.pushState(null, "", to);
window.history.pushState(null, "", exactLocation);
} else if (to.startsWith("/")) {
navigate(to);
closeApp();