瀏覽代碼

add a bit more content to the router example

Adrian Wannenmacher 2 年之前
父節點
當前提交
d866f6782e
共有 1 個文件被更改,包括 31 次插入14 次删除
  1. 31 14
      packages/router/examples/simple.rs

+ 31 - 14
packages/router/examples/simple.rs

@@ -15,31 +15,40 @@ fn App(cx: Scope) -> Element {
             // history: Box::new(MemoryHistory::with_initial_path("/apple").unwrap()),
             ..Default::default()
         },
-        &|| Segment::content(comp(RootIndex)).fixed("apple", comp(Apple)),
+        &|| {
+            Segment::content(comp(Home))
+                .fixed("apple", comp(Apple))
+                .fixed("potato", Route::content(comp(Potato)).name::<PotatoName>())
+                .fixed("earth_apple", named::<PotatoName>())
+        },
     );
 
     render! {
-        h1 { "Simple Example App" }
-        nav {
+            h1 { "Simple Example App" }
+            Outlet { }
             Link {
-                target: named::<RootIndex>(),
-                "Go to root"
-            }
+            target: named::<RootIndex>(),
+            "Go to root"
         }
-        Outlet { }
     }
 }
 
-fn RootIndex(cx: Scope) -> Element {
+fn Home(cx: Scope) -> Element {
     render! {
         h2 { "Root Index" }
         ul {
-            li {
-                Link {
-                    target: "/apple",
-                    "Read about apples…"
-                }
-            }
+            li { Link {
+                target: "/apple",
+                "Read about apples…"
+            } }
+            li { Link {
+                target: named::<PotatoName>(),
+                "Read about potatoes…"
+            } }
+            li { Link {
+                target: "/earth_apple",
+                "Read about earth apples (literal translation of a german word for potato)…"
+            } }
         }
     }
 }
@@ -53,3 +62,11 @@ fn Apple(cx: Scope) -> Element {
         }
     }
 }
+
+struct PotatoName;
+fn Potato(cx: Scope) -> Element {
+    render! {
+        h2 { "Potato" }
+        p { "The potato grows underground. There are many recipes involving potatoes." }
+    }
+}