File tree Expand file tree Collapse file tree 5 files changed +46
-1
lines changed Expand file tree Collapse file tree 5 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 1
- # SwiftWebUI Router
1
+ # [ SwiftWebUI] ( https://github.com/carson-katri/SwiftWebUI ) Router
2
2
3
3
A simple Router for SwiftWebUI:
4
4
@@ -39,3 +39,42 @@ module.exports = {
39
39
};
40
40
```
41
41
Now the server will always serve your index.html, no matter the route.
42
+
43
+ # Docs
44
+
45
+ ## ` Router `
46
+ A container for ` Routes ` .
47
+ Uses ` location.pathname ` to resolve which ` Route ` to render:
48
+ ``` swift
49
+ Router {
50
+ ...
51
+ }
52
+ ```
53
+
54
+ ## ` Route `
55
+ A map from a path to a View
56
+ Path can contains arguments, such as ` /artists/:artistId/song/:songId ` :
57
+ ``` swift
58
+ Route (to : " /artists/:artistId/song/:songId" ) { args in
59
+ VStack {
60
+ Text (" Artist: \( args[" artistId" ] ) " )
61
+ Text (" Song: \( args[" songId" ] ) " )
62
+ }
63
+ }
64
+ ```
65
+
66
+ ## Navigator
67
+ A way to navigate without using Views:
68
+ ``` swift
69
+ Navigator.back ()
70
+ Navigator.navigateTo ([" artists" , " 5" ])
71
+ Navigator.navigateTo (" /artists/5" )
72
+ ```
73
+
74
+ ## RouterLink
75
+ A button that navigates to the specified path
76
+ ``` swift
77
+ RouterLink (to : " /artists" ) {
78
+ Text (" Back" )
79
+ }
80
+ ```
Original file line number Diff line number Diff line change 6
6
//
7
7
import JavaScriptKit
8
8
9
+ /// A way to navigate without using Views
9
10
public struct Navigator {
10
11
public static func back( ) {
11
12
_ = JSObjectRef . global. history. object? . back ? ( )
Original file line number Diff line number Diff line change 7
7
import SwiftWebUI
8
8
import JavaScriptKit
9
9
10
+ /// A map from a path to a View
11
+ /// Path can contains arguments, such as `/artists/:artistId/song/:songId`
10
12
public struct Route : View {
11
13
let path : [ String ]
12
14
let content : AnyView
Original file line number Diff line number Diff line change 8
8
import SwiftWebUI
9
9
import JavaScriptKit
10
10
11
+ /// A container for `Route`s.
12
+ /// Uses `location.pathname` to resolve which `Route` to render
11
13
public struct Router : View {
12
14
let path : [ String ]
13
15
let routes : [ Route ]
Original file line number Diff line number Diff line change 7
7
8
8
import SwiftWebUI
9
9
10
+ /// A button that navigates to the specified path
10
11
public struct RouterLink < Content: View > : View {
11
12
let destination : String
12
13
let content : Content
You can’t perform that action at this time.
0 commit comments