-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(name-route): add support for named route
- Loading branch information
Showing
5 changed files
with
122 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from trame.app import get_server | ||
from trame.ui.html import DivLayout | ||
from trame.ui.router import RouterViewLayout | ||
from trame.widgets import html, router | ||
|
||
server = get_server() | ||
server.client_type = "vue2" | ||
state, ctrl = server.state, server.controller | ||
|
||
# --------------------------------------------------------- | ||
# home | ||
# --------------------------------------------------------- | ||
with RouterViewLayout(server, "/", name="content"): | ||
html.Div("home - content") | ||
|
||
with RouterViewLayout(server, "/", name="side"): | ||
html.Div("home - side") | ||
|
||
# --------------------------------------------------------- | ||
# foo | ||
# --------------------------------------------------------- | ||
with RouterViewLayout(server, "/foo", name="content"): | ||
html.Div("foo - content") | ||
|
||
with RouterViewLayout(server, "/foo", name="side"): | ||
html.Div("foo - side") | ||
|
||
# --------------------------------------------------------- | ||
# bar | ||
# --------------------------------------------------------- | ||
with RouterViewLayout(server, "/bar", name="content"): | ||
html.Div("bar - content") | ||
|
||
with RouterViewLayout(server, "/bar", name="side"): | ||
html.Div("bar - side") | ||
|
||
# --------------------------------------------------------- | ||
# Main UI | ||
# --------------------------------------------------------- | ||
with DivLayout(server) as layout: | ||
with html.Div("toolbar", style="border: solid 1px black;"): | ||
router.RouterLink("Home", to="/") | ||
router.RouterLink("Foo", to="/foo") | ||
router.RouterLink("Bar", to="/bar") | ||
|
||
with html.Div("side", style="border: solid 1px black;"): | ||
router.RouterView(name="side") | ||
|
||
with html.Div("content", style="border: solid 1px black;"): | ||
router.RouterView(name="content") | ||
|
||
print(layout) | ||
|
||
|
||
@ctrl.add("on_server_ready") | ||
def debug(trame__routes, **state): | ||
print(json.dumps(trame__routes, indent=2)) | ||
|
||
|
||
if __name__ == "__main__": | ||
server.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,5 @@ | |
title=("`Bar: Id ${id}`",), | ||
) | ||
|
||
print(c) | ||
|
||
if __name__ == "__main__": | ||
server.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from trame.app import get_server | ||
from trame.ui.html import DivLayout | ||
from trame.ui.router import RouterViewLayout | ||
from trame.widgets import html, router | ||
|
||
server = get_server() | ||
server.client_type = "vue3" | ||
state, ctrl = server.state, server.controller | ||
|
||
# --------------------------------------------------------- | ||
# home | ||
# --------------------------------------------------------- | ||
with RouterViewLayout(server, "/", name="content"): | ||
html.Div("home - content") | ||
|
||
with RouterViewLayout(server, "/", name="side"): | ||
html.Div("home - side") | ||
|
||
# --------------------------------------------------------- | ||
# foo | ||
# --------------------------------------------------------- | ||
with RouterViewLayout(server, "/foo", name="content"): | ||
html.Div("foo - content") | ||
|
||
with RouterViewLayout(server, "/foo", name="side"): | ||
html.Div("foo - side") | ||
|
||
# --------------------------------------------------------- | ||
# bar | ||
# --------------------------------------------------------- | ||
with RouterViewLayout(server, "/bar", name="content"): | ||
html.Div("bar - content") | ||
|
||
with RouterViewLayout(server, "/bar", name="side"): | ||
html.Div("bar - side") | ||
|
||
# --------------------------------------------------------- | ||
# Main UI | ||
# --------------------------------------------------------- | ||
with DivLayout(server) as layout: | ||
with html.Div("toolbar", style="border: solid 1px black;"): | ||
router.RouterLink("Home", to="/") | ||
router.RouterLink("Foo", to="/foo") | ||
router.RouterLink("Bar", to="/bar") | ||
|
||
with html.Div("side", style="border: solid 1px black;"): | ||
router.RouterView(name="side") | ||
|
||
with html.Div("content", style="border: solid 1px black;"): | ||
router.RouterView(name="content") | ||
|
||
if __name__ == "__main__": | ||
server.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters