@@ -25,10 +25,10 @@ npm i effector effector-react react
25
25
Wrap your app into this:
26
26
27
27
``` tsx
28
- import { createHistoryRouter } from ' atomic-router'
29
- import { RouterProvider , Route } from ' atomic-router-react'
28
+ import { createHistoryRouter } from " atomic-router" ;
29
+ import { RouterProvider , Route } from " atomic-router-react" ;
30
30
31
- import { HomePage } from ' ./routes'
31
+ import { HomePage } from " ./routes" ;
32
32
33
33
const router = createHistoryRouter ({ routes });
34
34
@@ -49,7 +49,7 @@ Simple usage:
49
49
import { createRoute } from ' atomic-router'
50
50
import { Link } from ' atomic-router-react'
51
51
52
- const homeRoute = createRoute <{postId : string }> ()
52
+ const homeRoute = createRoute ()
53
53
const postRoute = createRoute <{postId: string }>()
54
54
55
55
<Link to = { homeRoute } >Route link</Link >
@@ -60,21 +60,96 @@ const postRoute = createRoute<{postId:string}>()
60
60
All params:
61
61
62
62
``` tsx
63
- import { Link } from ' atomic-router-react'
63
+ import { Link } from " atomic-router-react" ;
64
64
65
65
<Link
66
66
to = { route }
67
- params = { { foo: ' bar' }}
68
- query = { { bar: ' baz' }}
67
+ params = { { foo: " bar" }}
68
+ query = { { bar: " baz" }}
69
69
activeClassName = " font-semibold text-red-400"
70
70
inactiveClassName = " opacity-80"
71
- />
71
+ />;
72
+ ```
73
+
74
+ ### ` createRoutesView ` - render routes
75
+
76
+ ``` tsx
77
+ import { createRouteView , RouterProvider } from " atomic-router-react" ;
78
+
79
+ // { route: RouteInstance<...>, view: FC<...> }
80
+ import * as Home from " @/pages/home" ;
81
+ import * as Post from " @/pages/post" ;
82
+
83
+ import { router } from " @/app/routing" ;
84
+
85
+ const RoutesView = createRoutesView ({
86
+ routes: [
87
+ { route: Home .route , view: Home .Page },
88
+ { route: Post .route , view: Post .Page },
89
+ ],
90
+ otherwise : () => {
91
+ return <div >Page not found!</div >;
92
+ },
93
+ });
94
+
95
+ const App = () => {
96
+ return (
97
+ <RouterProvider router = { router } >
98
+ <RoutesView />
99
+ </RouterProvider >
100
+ );
101
+ };
72
102
```
73
103
104
+ You can also set only a part of ` createRoutesView ` config on create and pass the rest of it via props:
105
+
106
+ ``` tsx
107
+ // Set specific otherwise view
108
+ const RoutesView = createRoutesView ({
109
+ otherwise: SpecificNotFound ,
110
+ });
111
+
112
+ // Pass the routes as a prop
113
+ <RoutesView routes = { routes } />;
114
+ ```
115
+
116
+ ### ` createRouteView ` - render view if route is opened
117
+
118
+ ``` tsx
119
+ import { createRoute } from " atomic-router" ;
120
+ import { createRouteView } from " atomic-router-react" ;
121
+ import { restore , createEffect } from " effector" ;
122
+
123
+ const homeRoute = createRoute ();
124
+
125
+ const getPostsFx = createEffect (/* ... */ );
126
+
127
+ const $posts = restore (getPostsFx , []);
128
+
129
+ const postsLoadedRoute = chainRoute ({
130
+ route ,
131
+ beforeOpen: getPostsFx ,
132
+ });
133
+
134
+ const PostsList = createRouteView ({
135
+ route: postsLoadedRoute ,
136
+ view : () => {
137
+ const posts = useStore ($posts );
138
+
139
+ return ; /* ... */
140
+ },
141
+ otherwise : () => {
142
+ return <div >Loading...</div >;
143
+ },
144
+ });
145
+ ```
146
+
147
+ Like in ` createRoutesView ` , you can set only a part of ` createRouteView ` config on create and pass the rest of it via props.
148
+
74
149
### ` Route ` - render route
75
150
76
151
``` tsx
77
- import { Route } from ' atomic-router-react'
152
+ import { Route } from " atomic-router-react" ;
78
153
79
- <Route route = { homeRoute } view = { HomePage } />
154
+ <Route route = { homeRoute } view = { HomePage } />;
80
155
```
0 commit comments