Merged in feat/BOOK-434-users-should-redirect-to- (pull request #3154)
* feat(BOOK-434): Moved redirect to middleware layer * feat(BOOK-434): Updated to handle no filters available scenario Approved-by: Erik Tiekstra
This commit is contained in:
@@ -40,8 +40,11 @@ export const middleware: NextMiddleware = async (request) => {
|
||||
if (incomingPathNameParts.length >= 2) {
|
||||
const subpage = incomingPathNameParts.pop()
|
||||
if (subpage) {
|
||||
const { contentType: parentContentType, uid: parentUid } =
|
||||
await getUidAndContentTypeByPath(incomingPathNameParts.join("/"))
|
||||
const {
|
||||
contentType: parentContentType,
|
||||
seoFilters,
|
||||
uid: parentUid,
|
||||
} = await getUidAndContentTypeByPath(incomingPathNameParts.join("/"))
|
||||
|
||||
if (parentUid) {
|
||||
switch (parentContentType) {
|
||||
@@ -53,8 +56,18 @@ export const middleware: NextMiddleware = async (request) => {
|
||||
break
|
||||
case PageContentTypeEnum.destinationCityPage:
|
||||
case PageContentTypeEnum.destinationCountryPage:
|
||||
// E.g. Active filters inside destination pages to filter hotels.
|
||||
// Validate Seo Filters from CMS and redirect if not found
|
||||
if (!seoFilters?.includes(subpage)) {
|
||||
return NextResponse.redirect(
|
||||
new URL(incomingPathNameParts.join("/"), nextUrl),
|
||||
{
|
||||
status: 301,
|
||||
}
|
||||
)
|
||||
}
|
||||
// E.g. Active Seo filters inside destination pages to filter hotels.
|
||||
searchParams.set("filterFromUrl", subpage)
|
||||
|
||||
contentType = parentContentType
|
||||
uid = parentUid
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user