Skip to content
Snippets Groups Projects
Commit f6dd2828 authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Fix double loading of legacy pages when navigated from another legacy page

parent 95971d91
No related branches found
No related tags found
1 merge request!1278Resolve "Some legacy pages apparently get build up/rendered twice"
Pipeline #134962 passed with warnings
......@@ -13,6 +13,7 @@ Fixed
~~~~~
* Notifications were not properly shown in the frontend.
* When navigating from legacy to legacy page, the latter would reload once for no reason.
`3.1.1` - 2023-07-01
--------------------
......
......@@ -21,7 +21,7 @@
</message-box>
<iframe
v-else
:src="'/django' + $route.path + queryString"
:src="iFrameSrc"
:height="iFrameHeight + 'px'"
class="iframe-fullsize"
@load="load"
......@@ -41,6 +41,7 @@ export default {
data: function () {
return {
iFrameHeight: 0,
iFrameSrc: undefined,
};
},
computed: {
......@@ -53,13 +54,16 @@ export default {
},
},
methods: {
getIFrameURL() {
const location = this.$refs.contentIFrame.contentWindow.location;
const url = new URL(location);
return url;
},
/** Handle iframe data after inner page loaded */
load() {
// Write new location of iframe back to Vue Router
const location = this.$refs.contentIFrame.contentWindow.location;
const url = new URL(location);
const path = url.pathname.replace(/^\/django/, "");
const pathWithQueryString = path + encodeURI(url.search);
const path = this.getIFrameURL().pathname.replace(/^\/django/, "");
const pathWithQueryString = path + encodeURI(this.getIFrameURL().search);
const routePath =
path.charAt(path.length - 1) === "/" &&
this.$route.path.charAt(path.length - 1) !== "/"
......@@ -103,15 +107,33 @@ export default {
},
},
watch: {
$route() {
$route(newRoute) {
// Show loading animation once route changes
this.$root.contentLoading = true;
// Only reload iFrame content when navigation comes from outsite the iFrame
const path = this.getIFrameURL().pathname.replace(/^\/django/, "");
const routePath =
path.charAt(path.length - 1) === "/" &&
newRoute.path.charAt(path.length - 1) !== "/"
? newRoute.path + "/"
: newRoute.path;
if (path !== routePath) {
this.$refs.contentIFrame.contentWindow.location =
"/django" + this.$route.path + this.queryString;
} else {
this.$root.contentLoading = false;
}
// Scroll to top only when route changes to not affect form submits etc.
// A small duration to avoid flashing of the UI
this.$vuetify.goTo(0, { duration: 10 });
},
},
mounted() {
this.iFrameSrc = "/django" + this.$route.path + this.queryString;
},
name: "LegacyBaseTemplate",
};
</script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment