File tree Expand file tree Collapse file tree 3 files changed +41
-24
lines changed Expand file tree Collapse file tree 3 files changed +41
-24
lines changed Original file line number Diff line number Diff line change @@ -13,29 +13,35 @@ import type { Params, RouteName } from "../../routes/routes";
13
13
defined in this project. To link outside, use <a></a> tags as usual.
14
14
*/
15
15
16
+ type Route = {
17
+ pathParams ?: Params ;
18
+ queryParams ?: Params ;
19
+ routeName : RouteName ;
20
+ } ;
21
+
16
22
// Extract pathParams from the routeName
17
- type AppLinkProps < R extends RouteName > = {
23
+ type AppLinkProps = {
18
24
children : React . ReactNode ;
19
25
className ?: string ;
20
- pathParams ?: Params ;
21
- queryParams ?: Params ;
22
- routeName : R ;
26
+ route : Route ;
23
27
targetBlank ?: boolean ;
28
+ replace ?: boolean ;
29
+ preventScrollReset ?: boolean ;
30
+ state ?: any ;
31
+ reloadDocument ?: boolean ;
24
32
} ;
25
33
26
34
const defaultProps = {
27
35
className : "" ,
28
- pathParams : { } ,
29
- queryParams : { } ,
30
36
targetBlank : false ,
37
+ replace : false ,
38
+ preventScrollReset : false ,
39
+ reloadDocument : false ,
31
40
} ;
32
41
33
- const AppLink = < R extends RouteName > ( props : AppLinkProps < R > ) => {
34
- const routePath = getRouteFor (
35
- props . routeName ,
36
- props . pathParams ,
37
- props . queryParams ,
38
- ) ;
42
+ const AppLink = ( props : AppLinkProps ) => {
43
+ const { routeName, pathParams, queryParams } = props . route ;
44
+ const routePath = getRouteFor ( routeName , pathParams , queryParams ) ;
39
45
let targetBlankProps = { } ;
40
46
if ( props . targetBlank ) {
41
47
targetBlankProps = {
@@ -44,7 +50,15 @@ const AppLink = <R extends RouteName>(props: AppLinkProps<R>) => {
44
50
} ;
45
51
}
46
52
return (
47
- < Link className = { props . className } to = { routePath } { ...targetBlankProps } >
53
+ < Link
54
+ className = { props . className }
55
+ to = { routePath }
56
+ replace = { props . replace }
57
+ preventScrollReset = { props . preventScrollReset }
58
+ state = { props . state }
59
+ reloadDocument = { props . reloadDocument }
60
+ { ...targetBlankProps }
61
+ >
48
62
{ props . children }
49
63
</ Link >
50
64
) ;
Original file line number Diff line number Diff line change @@ -13,26 +13,24 @@ import type { Params, RouteName } from "../../routes/routes";
13
13
defined in this project. To link outside, use <a></a> tags as usual.
14
14
*/
15
15
16
- type AppRedirectProps < R extends RouteName > = {
16
+ type Route = {
17
17
pathParams ?: Params ;
18
18
queryParams ?: Params ;
19
- routeName : R ;
19
+ routeName : RouteName ;
20
20
} ;
21
21
22
- const defaultProps = {
23
- pathParams : { } ,
24
- queryParams : { } ,
22
+ type AppRedirectProps = {
23
+ route : Route ;
25
24
} ;
26
25
27
- const AppRedirect = < R extends RouteName > ( props : AppRedirectProps < R > ) => {
26
+ const AppRedirect = ( props : AppRedirectProps ) => {
27
+ const { routeName, pathParams, queryParams } = props . route ;
28
28
const goToPage = useGoToPage ( ) ;
29
29
useEffect ( ( ) => {
30
- goToPage ( props . routeName , props . pathParams , props . queryParams ) ;
30
+ goToPage ( routeName , pathParams , queryParams ) ;
31
31
} , [ ] ) ;
32
32
33
33
return null ;
34
34
} ;
35
35
36
- AppRedirect . defaultProps = defaultProps ;
37
-
38
36
export { AppRedirect } ;
Original file line number Diff line number Diff line change @@ -10,11 +10,16 @@ export const Navbar = () => (
10
10
< Container >
11
11
< div className = { styles . internalContainer } >
12
12
< div >
13
- < AppLink routeName = { RouteName . Home } > Logo goes here</ AppLink >
13
+ < AppLink route = { { routeName : RouteName . Home } } >
14
+ Logo goes here
15
+ </ AppLink >
14
16
</ div >
15
17
< div className = { styles . rightContainer } >
16
18
< nav >
17
- < AppLink className = { globalStyles . link } routeName = { RouteName . About } >
19
+ < AppLink
20
+ className = { globalStyles . link }
21
+ route = { { routeName : RouteName . About } }
22
+ >
18
23
About
19
24
</ AppLink >
20
25
</ nav >
You can’t perform that action at this time.
0 commit comments