diff --git a/addons/website/static/src/client_actions/website_preview/website_preview.js b/addons/website/static/src/client_actions/website_preview/website_preview.js
index fa10a20ad42..4d40f9a2a32 100644
--- a/addons/website/static/src/client_actions/website_preview/website_preview.js
+++ b/addons/website/static/src/client_actions/website_preview/website_preview.js
@@ -35,6 +35,10 @@ export class WebsitePreview extends Component {
isBlocked: false,
showLoader: false,
});
+ // The params used to configure the context should be ignored when the
+ // action is restored (example: click on the breadcrumb).
+ this.isRestored = this.props.action.jsId === this.websiteService.actionJsId;
+ this.websiteService.actionJsId = this.props.action.jsId;
useBus(this.websiteService.bus, 'BLOCK', (event) => this.block(event.detail));
useBus(this.websiteService.bus, 'UNBLOCK', () => this.unblock());
@@ -57,12 +61,7 @@ export class WebsitePreview extends Component {
useEffect(() => {
this.websiteService.currentWebsiteId = this.websiteId;
-
- // The params used to configure the context should be ignored when
- // the action is restored (example: click on the breadcrumb).
- const isRestored = this.props.action.jsId === this.websiteService.actionJsId;
- this.websiteService.actionJsId = this.props.action.jsId;
- if (isRestored) {
+ if (this.isRestored) {
return;
}
this.websiteService.context.showNewContentModal = this.props.action.context.params && this.props.action.context.params.display_new_content;
@@ -95,6 +94,8 @@ export class WebsitePreview extends Component {
this.env.services.messaging.modelManager.messagingCreatedPromise.then(() => {
this.env.services.messaging.modelManager.messaging.update({ isWebsitePreviewOpen: false });
});
+ const { pathname, search, hash } = this.iframe.el.contentWindow.location;
+ this.websiteService.lastUrl = `${pathname}${search}${hash}`;
this.websiteService.currentWebsiteId = null;
this.websiteService.websiteRootInstance = undefined;
this.websiteService.pageDocument = null;
@@ -189,28 +190,27 @@ export class WebsitePreview extends Component {
}
get path() {
- let path = this.websiteService.editedObjectPath;
- if (!path) {
- path = this.props.action.context.params && this.props.action.context.params.path;
- if (path) {
- const url = new URL(path, window.location.origin);
- if (this._isTopWindowURL(url)) {
- // If the client action is initialized with a path that
- // should not be opened inside the iframe (= something we
- // would want to open on the top window), we consider that
- // this is not a valid flow. Instead of trying to open it on
- // the top window, we initialize the iframe with the
- // website homepage...
- path = '/';
- } else {
- // ... otherwise, the path still needs to be normalized (as
- // it would be if the given path was used as an href of a
- // element).
- path = url.pathname + url.search + url.hash;
- }
- } else {
+ let path = this.isRestored
+ ? this.websiteService.lastUrl
+ : this.props.action.context.params && this.props.action.context.params.path;
+
+ if (path) {
+ const url = new URL(path, window.location.origin);
+ if (this._isTopWindowURL(url)) {
+ // If the client action is initialized with a path that should
+ // not be opened inside the iframe (= something we would want to
+ // open on the top window), we consider that this is not a valid
+ // flow. Instead of trying to open it on the top window, we
+ // initialize the iframe with the website homepage...
path = '/';
+ } else {
+ // ... otherwise, the path still needs to be normalized (as it
+ // would be if the given path was used as an href of a
+ // element).
+ path = url.pathname + url.search + url.hash;
}
+ } else {
+ path = '/';
}
return path;
}
diff --git a/addons/website/static/src/services/website_service.js b/addons/website/static/src/services/website_service.js
index 046ab059018..cfffab1ebe4 100644
--- a/addons/website/static/src/services/website_service.js
+++ b/addons/website/static/src/services/website_service.js
@@ -32,7 +32,7 @@ export const websiteService = {
let fullscreen;
let pageDocument;
let contentWindow;
- let editedObjectPath;
+ let lastUrl;
let websiteRootInstance;
let Wysiwyg;
let isRestrictedEditor;
@@ -151,11 +151,11 @@ export const websiteService = {
websiteRootInstance = rootInstance;
context.isPublicRootReady = !!rootInstance;
},
- set editedObjectPath(path) {
- editedObjectPath = path;
+ set lastUrl(url) {
+ lastUrl = url;
},
- get editedObjectPath() {
- return editedObjectPath;
+ get lastUrl() {
+ return lastUrl;
},
get isRestrictedEditor() {
return isRestrictedEditor === true;
diff --git a/addons/website/static/src/systray_items/edit_in_backend.js b/addons/website/static/src/systray_items/edit_in_backend.js
index 93408c89730..329b4a9a38c 100644
--- a/addons/website/static/src/systray_items/edit_in_backend.js
+++ b/addons/website/static/src/systray_items/edit_in_backend.js
@@ -3,7 +3,7 @@
import { registry } from "@web/core/registry";
import { useService, useBus } from "@web/core/utils/hooks";
-const { Component, onWillStart, onMounted, useState } = owl;
+const { Component, onWillStart, useState } = owl;
const websiteSystrayRegistry = registry.category('website_systray');
@@ -15,16 +15,10 @@ export class EditInBackendSystray extends Component {
onWillStart(this._updateMainObjectName);
useBus(websiteSystrayRegistry, 'CONTENT-UPDATED', this._updateMainObjectName);
-
- onMounted(() => {
- this.websiteService.editedObjectPath = null;
- });
}
editInBackend() {
const { metadata: { mainObject } } = this.websiteService.currentWebsite;
- const location = this.websiteService.contentWindow.location;
- this.websiteService.editedObjectPath = location.pathname + location.search + location.hash;
this.actionService.doAction({
res_model: mainObject.model,
res_id: mainObject.id,