Skip to content

Commit 8ebb007

Browse files
authored
feat: home page jump adjustment (#11357)
<!-- Before opening a pull request, please read the [contributing guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md) first --> <!-- start pr-codex --> --- ## PR-Codex overview This PR introduces a visitor redirect middleware, updates routing paths, and modifies components to improve user navigation and experience on the home page. ### Detailed summary - Updated `redirects` in `next.config.mjs` to redirect `/send` to `/swap`. - Changed `href` in `menu.test.tsx.snap` from `/` to `/home`. - Updated `Menu.tsx` to link to `/home`. - Created `IndexPage` in `home.tsx` using `Suspense` for `HomeV2`. - Added new path for `/home` in `meta.ts`. - Included `visitorRedirectMiddleware` in `middleware.ts`. - Implemented cookie logic in `visitor-rule-middleware.ts` to track first-time visitors and redirect them accordingly. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 78776c1 commit 8ebb007

File tree

7 files changed

+49
-8
lines changed

7 files changed

+49
-8
lines changed

apps/web/next.config.mjs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,6 @@ const config = {
158158
},
159159
async redirects() {
160160
return [
161-
{
162-
source: '/home',
163-
destination: '/',
164-
permanent: false
165-
},
166161
{
167162
source: '/send',
168163
destination: '/swap',

apps/web/src/config/constants/meta.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const getPathList = memoize((t: ContextApi['t']): PathList => {
1818
return {
1919
paths: {
2020
'/': { title: t('Home') },
21+
'/home': { title: t('Home') },
2122
'/swap': { basePath: true, title: t('Exchange'), image: `${ASSET_CDN}/web/og/swap.jpg` },
2223
'/limit-orders': { basePath: true, title: t('Limit Orders'), image: `${ASSET_CDN}/web/og/limit.jpg` },
2324
'/add': { basePath: true, title: t('Add Liquidity'), image: `${ASSET_CDN}/web/og/liquidity.jpg` },

apps/web/src/middleware.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ import { withClientId } from 'middlewares/client-id-middleware'
44
import { withGeoBlock } from 'middlewares/geo-block-middleware'
55
import { withUserIp } from 'middlewares/ip-address-middleware'
66
import { stackMiddlewares } from 'middlewares/stack-middleware'
7+
import { visitorRedirectMiddleware } from 'middlewares/visitor-rule-middleware'
78

8-
export const middleware = stackMiddlewares([withClientId, withGeoBlock, withUserIp, withABTesting])
9+
export const middleware = stackMiddlewares([
10+
withClientId,
11+
withGeoBlock,
12+
withUserIp,
13+
withABTesting,
14+
visitorRedirectMiddleware,
15+
])
916

1017
export const config = {
1118
matcher: [
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { NextFetchEvent, NextResponse } from 'next/server'
2+
import { ExtendedNextReq, MiddlewareFactory, NextMiddleware } from './types'
3+
4+
export const visitorRedirectMiddleware: MiddlewareFactory = (next: NextMiddleware) => {
5+
return async (request: ExtendedNextReq, _next: NextFetchEvent) => {
6+
const visited = request.cookies.get('visited')
7+
8+
if (visited) {
9+
if (request.nextUrl.pathname === '/') {
10+
return NextResponse.redirect(new URL('/swap', request.url))
11+
}
12+
} else {
13+
const response = NextResponse.next()
14+
response.cookies.set('visited', 'true', {
15+
path: '/',
16+
maxAge: 60 * 60 * 24 * 365, // 1 year
17+
})
18+
return response
19+
}
20+
21+
return next(request, _next)
22+
}
23+
}

apps/web/src/pages/home.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Suspense } from 'react'
2+
import { HomeV2 } from 'views/HomeV2'
3+
4+
const IndexPage = () => {
5+
return (
6+
<Suspense>
7+
<HomeV2 />
8+
</Suspense>
9+
)
10+
}
11+
12+
IndexPage.chains = []
13+
IndexPage.isShowV4IconButton = true
14+
15+
export default IndexPage

packages/uikit/src/__tests__/widgets/__snapshots__/menu.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ exports[`renders correctly 1`] = `
768768
<a
769769
aria-label="Pancake home page"
770770
class="c5"
771-
href="/"
771+
href="/home"
772772
>
773773
<svg
774774
class="c6 mobile-icon"

packages/uikit/src/widgets/Menu/Menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const Menu: React.FC<React.PropsWithChildren<NavProps>> = ({
150150
{banner && isMounted && <TopBannerContainer height={topBannerHeight}>{banner}</TopBannerContainer>}
151151
<StyledNav id="nav">
152152
<Flex>
153-
{logoComponent ?? <Logo href={homeLink?.href ?? "/"} />}
153+
{logoComponent ?? <Logo href={homeLink?.href ?? "/home"} />}
154154
<AtomBox display={{ xs: "none", lg: "block" }}>
155155
<MenuItems
156156
ml="24px"

0 commit comments

Comments
 (0)