-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from DavidBerger98/add-router-example
Add vue-router helper classes and example
- Loading branch information
Showing
3 changed files
with
131 additions
and
17 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,64 @@ | ||
from trame.layouts import SinglePageWithDrawer | ||
from trame.html import Template, vuetify, router | ||
|
||
layout = SinglePageWithDrawer("Multi-Page demo") | ||
layout.title.set_text("Multi-Page demo") | ||
|
||
# There are two ways to register a route | ||
home_template = vuetify.VCard() | ||
with home_template: | ||
vuetify.VCardTitle("This is home") | ||
|
||
foo_template = vuetify.VCard() | ||
with foo_template: | ||
vuetify.VCardTitle("This is foo") | ||
with vuetify.VCardText(): | ||
vuetify.VBtn("Take me back", click="$router.back()") | ||
|
||
# You can add a route with add_route | ||
layout.add_route("home", "/", home_template) | ||
layout.add_route("foo", "/foo", foo_template) | ||
|
||
# or use the contextmanager 'with_route' | ||
with layout.with_route("bar", "/bar/:id", vuetify.VCard()): | ||
vuetify.VCardTitle("This is bar with ID '{{ $route.params.id }}'") | ||
|
||
# add <router-view /> | ||
with layout.content: | ||
with vuetify.VContainer(): | ||
router.RouterView() | ||
|
||
# add router buttons to the drawer | ||
with layout.drawer: | ||
with vuetify.VList(shaped=True, v_model=("selectedRoute", 0)): | ||
vuetify.VSubheader("Routes") | ||
|
||
with vuetify.VListItem(to="/"): | ||
with vuetify.VListItemIcon(): | ||
vuetify.VIcon("mdi-home") | ||
with vuetify.VListItemContent(): | ||
vuetify.VListItemTitle("Home") | ||
|
||
with vuetify.VListItem(to="/foo"): | ||
with vuetify.VListItemIcon(): | ||
vuetify.VIcon("mdi-food") | ||
with vuetify.VListItemContent(): | ||
vuetify.VListItemTitle("Foo") | ||
|
||
with vuetify.VListGroup(value=("true",), sub_group=True): | ||
with Template(v_slot_activator=True): | ||
vuetify.VListItemTitle("Bars") | ||
with vuetify.VListItemContent(): | ||
with vuetify.VListItem(v_for="id in [1,2,3]", to=("'/bar/' + id",)): | ||
with vuetify.VListItemIcon(): | ||
vuetify.VIcon("mdi-peanut-outline") | ||
with vuetify.VListItemContent(): | ||
vuetify.VListItemTitle("Bar") | ||
vuetify.VListItemSubtitle("ID '{{id}}'") | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Main | ||
# ----------------------------------------------------------------------------- | ||
|
||
if __name__ == "__main__": | ||
layout.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,18 @@ | ||
from trame.internal.app import get_app_instance | ||
from trame.html import AbstractElement | ||
from pywebvue.modules import Router | ||
|
||
# Make sure used module is available | ||
_app = get_app_instance() | ||
_app.enable_module(Router) | ||
|
||
|
||
class RouterView(AbstractElement): | ||
def __init__(self, children=None, **kwargs): | ||
super().__init__("router-view", children=children, **kwargs) | ||
|
||
|
||
class RouterLink(AbstractElement): | ||
def __init__(self, children=None, **kwargs): | ||
super().__init__("router-link", children=children, **kwargs) | ||
self._attr_names += ["to"] |
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