File tree Expand file tree Collapse file tree 6 files changed +32
-20
lines changed
Expand file tree Collapse file tree 6 files changed +32
-20
lines changed Original file line number Diff line number Diff line change 2727 },
2828 "plugins" : [" react-hooks" , " react-refresh" ],
2929 "rules" : {
30+ "@typescript-eslint/no-throw-literal" : " off" ,
3031 "react/react-in-jsx-scope" : " off" ,
3132 "react/require-default-props" : " off" ,
3233 "react-hooks/rules-of-hooks" : " error" ,
Original file line number Diff line number Diff line change 1- import { HTMLAttributes , PropsWithChildren , Ref } from 'react' ;
1+ import { forwardRef , HTMLAttributes , PropsWithChildren } from 'react' ;
2+
3+ type ButtonProps = PropsWithChildren < HTMLAttributes < HTMLButtonElement > > ;
4+
5+ const Button = forwardRef < HTMLButtonElement , ButtonProps > ( ( props , ref ) => {
6+ const { children, className, onClick } = props ;
27
3- function Button ( {
4- ref,
5- children,
6- className,
7- onClick,
8- } : PropsWithChildren < HTMLAttributes < HTMLButtonElement > > & {
9- ref ?: Ref < HTMLButtonElement > ;
10- } ) {
118 return (
129 < button
1310 ref = { ref }
@@ -18,6 +15,8 @@ function Button({
1815 { children }
1916 </ button >
2017 ) ;
21- }
18+ } ) ;
19+
20+ Button . displayName = 'Button' ;
2221
2322export default Button ;
Original file line number Diff line number Diff line change 1- import { createFileRoute } from '@tanstack/react-router' ;
1+ import { createFileRoute , redirect } from '@tanstack/react-router' ;
22
33import { refresh , useAuthStore } from '@/features/auth' ;
44
@@ -8,14 +8,16 @@ export const Route = createFileRoute('/my')({
88 component : MyPage ,
99 beforeLoad : ( ) => {
1010 const { isLogin, setAuthInformation } = useAuthStore . getState ( ) ;
11- if ( ! isLogin ( ) )
12- refresh ( )
11+
12+ if ( ! isLogin ( ) ) {
13+ return refresh ( )
1314 . then ( ( res ) => {
1415 setAuthInformation ( res ) ;
1516 } )
1617 . catch ( ( ) => {
17- // eslint-disable-next-line @typescript-eslint/no-throw-literal
18- window . location . href = '/' ;
18+ throw redirect ( { to : '/' } ) ;
1919 } ) ;
20+ }
21+ return Promise . resolve ( ) ;
2022 } ,
2123} ) ;
Original file line number Diff line number Diff line change 1- import { createFileRoute } from '@tanstack/react-router' ;
1+ import { createFileRoute , isRedirect , redirect } from '@tanstack/react-router' ;
22
33import { refresh , useAuthStore } from '@/features/auth' ;
44import { getSessionToken , useSessionStore } from '@/features/session' ;
@@ -52,8 +52,17 @@ export const Route = createFileRoute('/session/$sessionId/$questionId/')({
5252 response . questions . forEach ( ( question ) => {
5353 addQuestion ( question ) ;
5454 } ) ;
55+
56+ if (
57+ response . questions . every (
58+ ( question ) => question . questionId !== Number ( questionId ) ,
59+ )
60+ ) {
61+ throw redirect ( { to : `/session/${ sessionId } ` } ) ;
62+ }
5563 } catch ( e ) {
56- window . location . href = '/' ;
64+ if ( isRedirect ( e ) ) throw e ;
65+ throw redirect ( { to : '/' } ) ;
5766 }
5867 } ,
5968} ) ;
Original file line number Diff line number Diff line change 1- import { createFileRoute } from '@tanstack/react-router' ;
1+ import { createFileRoute , redirect } from '@tanstack/react-router' ;
22
33import { refresh , useAuthStore } from '@/features/auth' ;
44import { getSessionToken , useSessionStore } from '@/features/session' ;
@@ -51,7 +51,7 @@ export const Route = createFileRoute('/session/$sessionId/')({
5151 addQuestion ( question ) ;
5252 } ) ;
5353 } catch ( e ) {
54- window . location . href = '/' ;
54+ throw redirect ( { to : '/session' } ) ;
5555 }
5656 } ,
5757} ) ;
Original file line number Diff line number Diff line change 11import {
22 createFileRoute ,
33 Outlet ,
4+ redirect ,
45 ScrollRestoration ,
56} from '@tanstack/react-router' ;
67
@@ -10,7 +11,7 @@ import { ChattingList } from '@/components';
1011
1112export const Route = createFileRoute ( '/session' ) ( {
1213 beforeLoad : ( { location } ) => {
13- if ( location . pathname === '/session' ) window . location . href = '/' ;
14+ if ( location . pathname === '/session' ) throw redirect ( { to : '/' } ) ;
1415 } ,
1516 component : ( ) => (
1617 < div className = 'flex h-full w-full items-center justify-center gap-4 px-4 py-4 md:max-w-[1194px]' >
You can’t perform that action at this time.
0 commit comments