Skip to content

Commit d5e7025

Browse files
committed
fix: Redirect to /projects page from /
1 parent 0d7ec71 commit d5e7025

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

site/components/Redirect.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { render, waitFor } from "@testing-library/react"
2+
import singletonRouter from "next/router"
3+
import mockRouter from "next-router-mock"
4+
import React from "react"
5+
import { Redirect } from "./Redirect"
6+
7+
describe("Redirect", () => {
8+
// Reset the router to '/' before every test
9+
beforeEach(() => {
10+
mockRouter.setCurrentUrl("/")
11+
})
12+
13+
it("performs client-side redirect on render", async () => {
14+
// When
15+
render(<Redirect to="/workspaces/v2" />)
16+
17+
// Then
18+
await waitFor(() => {
19+
expect(singletonRouter).toMatchObject({ asPath: "/workspaces/v2" })
20+
})
21+
})
22+
})

site/components/Redirect.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ import React, { useEffect } from "react"
22
import { useRouter } from "next/router"
33

44
export interface RedirectProps {
5+
/**
6+
* The path to redirect to
7+
* @example '/projects'
8+
*/
59
to: string
610
}
711

12+
/**
13+
* Helper component to perform a client-side redirect
14+
*/
815
export const Redirect: React.FC<RedirectProps> = ({ to }) => {
916
const router = useRouter()
1017

@@ -13,4 +20,4 @@ export const Redirect: React.FC<RedirectProps> = ({ to }) => {
1320
}, [])
1421

1522
return null
16-
}
23+
}

site/components/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from "./Button"
22
export * from "./EmptyState"
33
export * from "./Page"
4-
export * from "./Redirect"
4+
export * from "./Redirect"

site/pages/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from "react"
22

33
import { Redirect } from "../components"
4-
import { ErrorSummary } from "../components/ErrorSummary"
54
import { FullScreenLoader } from "../components/Loader/FullScreenLoader"
65
import { useUser } from "../contexts/UserContext"
76

0 commit comments

Comments
 (0)