35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/examples/AdvancedRedirect.svelte:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 | to home
11 | to page 1
12 | to page 2
13 | this redirects to page1
14 | this redirects to page2
15 | this will not redirect to page2
16 | this redirects to home
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | NotFound
36 |
37 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2019-present Dmitry Kutran
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/doc/components/Example/index.svelte:
--------------------------------------------------------------------------------
1 |
5 |
6 |
40 |
41 |
Should be placed on the top of your application. Applies special listener for every <a> element and initializes routing state for application's tree.
39 |
Uses browser history API.
40 |
41 | ### <MemoryRouter />
42 |
43 |
The same as <Router> but uses in-memory history API.
44 |
45 | ### getHistory: Function
46 |
47 |
48 | Function that returns object of helper functions to work with history.
49 |
50 |
51 |
This function should be called in the component's initialization step bacause Router and MemoryRouter uses svelte's context API as a core approach
52 |
53 | #### Methods:
54 |
55 |
56 |
57 |
58 |
Name
59 |
Arguments
60 |
Description
61 |
62 |
63 |
64 |
65 |
push
66 |
path: String
67 |
Push path to the history
68 |
69 |
70 |
replace
71 |
path: String
72 |
Replace path in the current state of the history
73 |
74 |
75 |
back
76 |
-
77 |
Move back in the history
78 |
79 |
80 |
forward
81 |
-
82 |
Move forward in the history
83 |
84 |
85 |
86 |
87 | #### Stores:
88 |
89 |
90 |
91 |
92 |
Name
93 |
Subject
94 |
Description
95 |
96 |
97 |
98 |
99 |
currentPath
100 |
currentPath: String
101 |
Current path in history
102 |
103 |
104 |
stack (<MemoryRouter> only)
105 |
{ stack, hasNext, hasPrev }
106 |
Set of fields with memory histories' metadata
107 |
108 |
109 |
110 |
111 | ### navLink: Function
112 |
113 |
114 | Svelte action. Allows to control active class (show/hide it) in case of matching href attribute with current path of history. Active class name should be defined explicitly to be compiled with svelte.
115 |
Class name that will be assigned in case of pathes matches
144 |
145 |
146 |
147 |
148 | ### <Route />
149 |
150 |
151 | Specifies your route configuration.
152 |
153 |
154 |
155 | It is possible to define nested to routes.
156 | In this case all pathes will calculate relatively the parent path.
157 | Ex. If parent route defined as <Route path="/parent" /> and child as <Route path="/child" /> - in this case nested route will be resolved by path /parent/child.
158 |
159 |
160 |
161 |
162 |
163 |
Prop
164 |
Type
165 |
Default / required
166 |
Description
167 |
168 |
169 |
170 |
171 |
172 | path
173 |
174 |
String
175 |
required
176 |
177 |
Path to access the route.
178 |
Could be defined as template with required and optional parameters (ex. /pokemon/:id).
179 |
180 | If path matched than parameters passing inside components from lazy or component as property (ex. export let id) or could be accessed from let:params and passed to the slot.
181 |
182 |
183 |
184 |
185 |
186 | let:params
187 |
188 |
Object
189 |
null
190 |
Parameters resolved from path
191 |
192 |
193 |
exact
194 |
Boolean
195 |
false
196 |
197 |
Detects if path should have exactly matches
198 |
199 |
200 |
201 |
when
202 |
Boolean
203 |
true
204 |
205 |
Detects if route is using in current flow
206 |
207 |
208 |
209 |
component
210 |
SvelteComponent
211 |
null
212 |
213 |
Renders in case if path matched
214 |
215 |
216 |
217 |
lazy
218 |
() => Promise<SvelteComponent>
219 |
null
220 |
221 |
Function that returns promise that resolving the Svelte component
222 |
Loading starts only on the first route matching and after that component will cache
223 |
224 |
225 |
226 |
throttle
227 |
Number
228 |
0
229 |
230 |
Uses in a couple with lazy.
231 |
Determines minimal time (in ms) which component will not be displayed.
232 |
Necessary for preventing flash effect when switching pending state to component.
233 |
234 |
235 |
236 |
<slot />
237 |
SvelteSlot
238 |
-
239 |
240 |
Renders in the case if lazy or component props was't defined
241 |
242 |
243 |
244 |
<slot name="pending" />
245 |
SvelteSlot
246 |
-
247 |
248 |
Renders when component from lazy field is loading
249 |
250 |
251 |
252 |
<slot name="catch" />
253 |
SvelteSlot
254 |
-
255 |
256 |
Renders when component from lazy field is failed to load
257 |
258 |
259 |
260 |
261 |
262 | ### <Layout />
263 |
264 |
265 | Provides the possibility to declaratively define layouts around the group of routes and will be rendered only in the case if any path of these routes matches.
266 |
267 |
268 |
269 |
270 |
271 |
Prop
272 |
Type
273 |
Default / required
274 |
Description
275 |
276 |
277 |
278 |
279 |
component
280 |
SvelteComponent
281 |
required
282 |
283 | Layout component that wraps the group of routes. <slot/> content of <Layout> will be passed to it.
284 | Renders only in case if any path of inner routes matches.
285 |
286 |
287 |
288 |
when
289 |
Boolean
290 |
true
291 |
292 |
Detects if layout and it routes' group is using in current flow
293 |
294 |
295 |
296 |
<slot />
297 |
SvelteSlot
298 |
-
299 |
300 |
Will be passed to the component.
301 |
302 |
303 |
304 |
305 |
306 | ### <HashRoute />
307 |
308 |
309 | Extends <Route> without path property and expands with own ones.
310 |
311 |
312 | Route that displays content, when history hash (#) matches.
313 |
314 |
315 |
316 |
317 |
318 |
Prop
319 |
Type
320 |
Default / required
321 |
Description
322 |
323 |
324 |
325 |
326 |
hash
327 |
String
328 |
required
329 |
Should start with #
330 |
331 |
332 |
let:removeHash
333 |
Function
334 |
-
335 |
336 | Passes to component or lazy as property.
337 | Function that allows to remove hash from history.
338 | Usefull in a couple with modals etc.
339 |
340 |
341 |
342 |
343 |
344 | ### <Fallback />
345 |
346 |
347 | Extends <Route> without path property.
348 |
349 |
350 | Renders component from lazy, component or <slot /> if any defined route wasn't rendered.
351 | Usefull for 404 (NotFound) pages.
352 |
353 |
354 | ### <Redirect />
355 |
356 |
357 | Determines overriding of current location.
358 | Nested redirect will define from path relatively to the parent route's path.
359 |
360 |
361 |
362 |
363 |
364 |
Prop
365 |
Type
366 |
Default / required
367 |
Description
368 |
369 |
370 |
371 |
372 |
to
373 |
String
374 |
required
375 |
376 | Defines path to which redirect in case of from matched
377 |
378 |
379 |
380 |
from
381 |
String
382 |
'*'
383 |
384 | Determines the path that should be overrided.
385 | If * specified than redirect will be triggered from path that doesn't matched for any route.
386 |
387 |
388 |
389 |
exact
390 |
Boolean
391 |
false
392 |
393 | Detects if path of from property should have exactly matches
394 |
395 |
396 |
397 |
398 |
399 | ### <BeforeLeave />
400 |
401 |
402 | Provides possibility to prevent leaving from the page.
403 |
404 |
405 | Usefull if there is a form on the page and in the case of it's filled to prevent leaving.
406 |
407 |
408 |
409 |
410 |
411 |
Prop
412 |
Type
413 |
Default / required
414 |
Description
415 |
416 |
417 |
418 |
419 |
shouldDetectLeave
420 |
Boolean
421 |
true
422 |
Detects if leaving should be detected
423 |
424 |
425 |
let:isLeaving
426 |
Boolean
427 |
true
428 |
Detects if user trying to leave the page
429 |
430 |
431 |
let:cancelLeave
432 |
Function
433 |
-
434 |
Cancel transition from the page
435 |
436 |
437 |
let:acceptLeave
438 |
Function
439 |
-
440 |
Accept transition from the page. User will be moved to the page where he tried to go before.
441 |
442 |
443 |
<slot />
444 |
SvelteSlot
445 |
-
446 |
Child content of the component
447 |
448 |
449 |
450 |
451 | ### <Protected />
452 |
453 |
454 | Protects displaying of nested routes. If routes was wrapped with some content before - it (content) will be displayed in any case. Uses as an abstraction for <Layout /> but could be usefull in some special cases.
455 |
456 |
457 |
458 |
459 |
460 |
Prop
461 |
Type
462 |
Default / required
463 |
Description
464 |
465 |
466 |
467 |
468 |
when
469 |
Boolean
470 |
true
471 |
Detects if routes should be displayed in the subtree
472 |
473 |
474 |
475 |
476 | # TODO
477 |
478 | 1. Recipe for SSR
479 | 2. Unit tests
480 | 3. Typings
481 |
--------------------------------------------------------------------------------
/logo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------