Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

fix(default-theme): prevent from calling page resolver on static pages #1617

Merged
merged 4 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/default-theme/src/helpers/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ export const PAGE_SEARCH = "/search"
export const PAGE_ORDER_SUCCESS = "/order-success"
export const PAGE_ORDER_PAYMENT_FAILURE = "/payment-failure"
export const PAGE_WISHLIST = "/wishlist"
/**
*
* @param {vue-router Route} route
* @returns
*/
export const isStaticPage = (route) => !route?.name?.startsWith("all_")
11 changes: 7 additions & 4 deletions packages/default-theme/src/middleware/pages.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useBreadcrumbs, useCms } from "@shopware-pwa/composables"

import { isStaticPage } from "@/helpers/pages"
/**
* A place to plug in some actions during changing the pages/routes.
* For instance: broadcast events for specific page
Expand All @@ -10,10 +10,13 @@ export default async function ({ app, route, redirect }) {
clear()

const { search, currentSearchPathKey, page } = useCms(app)
if (route.path !== currentSearchPathKey.value) {
await search(route.path, route.query)
if (!isStaticPage(route) && route.path !== currentSearchPathKey.value) {
// route path shouldn't have virtual domain's prefix included in URL
// because it's no a part of URL in seo_urls SW6 table
const pathMatch = route?.params?.pathMatch
await search(pathMatch, route.query)
// redirect to the cannnical URL if current path does not match the canonical one
if (page.value && route.path !== page.value.canonicalPathInfo) {
if (page.value && pathMatch && pathMatch !== page.value.canonicalPathInfo) {
return redirect(app.$routing.getUrl(page.value.canonicalPathInfo))
}
}
Expand Down