-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop landing pages from rendering at the dynamic route #11354
Changes from all commits
d77303d
3141acd
b4aff0e
bbe2eec
0585eda
386a06c
bdc754d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,14 +185,11 @@ const EventPage: NextPage<EventProps> = ({ | |
url: '/events', | ||
text: 'Events', | ||
}, | ||
...event.series.map(series => { | ||
console.log(series); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just removed this log (I could see some logs in Kibana, unsure which ones they are but thought I'd remove the ones we don't need). |
||
return { | ||
url: linkResolver(series), | ||
text: series.title || '', | ||
prefix: 'Part of', | ||
}; | ||
}), | ||
...event.series.map(series => ({ | ||
url: linkResolver(series), | ||
text: series.title || '', | ||
prefix: 'Part of', | ||
})), | ||
scheduledIn | ||
? { | ||
url: linkResolver(scheduledIn), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,13 @@ export const getServerSideProps: GetServerSideProps< | |
const { pageId } = context.query; | ||
const siteSection = toMaybeString(context.params?.siteSection); | ||
|
||
if (!looksLikePrismicId(pageId)) { | ||
// We don't allow e.g. /visit-us/visit-us as it's a landing page | ||
// Should only display on /visit-us | ||
const isLandingPageRenderingAsSubPage = | ||
pageId === siteSection && | ||
context.resolvedUrl.indexOf(`/${siteSection}/${pageId}`) === 0; | ||
Comment on lines
+113
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little bit verbose to my taste, will take ideas on cleverer ways of checking this. |
||
|
||
if (!looksLikePrismicId(pageId) || isLandingPageRenderingAsSubPage) { | ||
return { notFound: true }; | ||
} | ||
|
||
|
@@ -123,10 +129,16 @@ export const getServerSideProps: GetServerSideProps< | |
const basicDocSiteSection = basicDocument.tags.find(t => | ||
isSiteSection(t) | ||
); | ||
const isLandingPage = basicDocSiteSection === pageId; | ||
|
||
const redirectUrl = | ||
isLandingPage || !basicDocSiteSection | ||
? `/${pageId}` | ||
: `/${basicDocSiteSection}/${pageId}`; | ||
|
||
return { | ||
redirect: { | ||
destination: `${basicDocSiteSection ? '/' + basicDocSiteSection : ''}/${basicDocument.uid}`, | ||
destination: redirectUrl, | ||
permanent: false, | ||
}, | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,9 +84,7 @@ const stageApiToggleCookie = createCookie({ | |
value: 'true', | ||
}); | ||
|
||
// TODO: context.addCookies should run for the first test of a suite (even on beforeAll/beforeEach) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This TODO is 3 yrs old, and we don't want all scenarios to have cookies added, so removing. |
||
|
||
const requiredCookies = useStageApis | ||
export const requiredCookies = useStageApis | ||
? [acceptCookieCookie, stageApiToggleCookie] | ||
: [acceptCookieCookie]; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
import { gotoWithoutCache, requiredCookies } from './helpers/contexts'; | ||
import { baseUrl } from './helpers/utils'; | ||
|
||
test.describe('Server-side redirection logic works as expected', () => { | ||
test('/pages/ route redirects to relevant URL', async ({ context, page }) => { | ||
await context.addCookies(requiredCookies); | ||
|
||
// Visit Us site section | ||
await gotoWithoutCache(`${baseUrl}/pages/accessibility`, page); | ||
await expect(page.url()).toEqual(`${baseUrl}/visit-us/accessibility`); | ||
|
||
// Orphan page | ||
await gotoWithoutCache(`${baseUrl}/pages/contact-us`, page); | ||
await expect(page.url()).toEqual(`${baseUrl}/contact-us`); | ||
}); | ||
|
||
test("Landing pages don't have a parent route", async ({ context, page }) => { | ||
await context.addCookies(requiredCookies); | ||
|
||
await gotoWithoutCache(`${baseUrl}/visit-us/visit-us`, page); | ||
await expect( | ||
page | ||
.getByRole('heading') | ||
.getByText('Not the Wellcome you were expecting?') | ||
).toBeVisible(); | ||
|
||
await gotoWithoutCache(`${baseUrl}/pages/visit-us`, page); | ||
await expect(page.url()).toEqual(`${baseUrl}/visit-us`); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean that if there is a sitesection tag, it would take precedence over
doc.siteSection
– and if so is that ok?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so yes, and if so it should still be the correct
siteSection
, so I'd say it's ok!