trame-router

raw JSON →
2.3.0 verified Mon Apr 27 auth: no python

Vue Router integration for trame, providing navigation and route management for trame applications. Current version 2.3.0, actively maintained as part of the trame ecosystem.

pip install trame-router
error ImportError: cannot import name 'RouterView' from 'trame_router'
cause Incorrect import path after version 2.0.0.
fix
Use 'from trame_router.widgets import RouterView'
error Vue warn: Component is missing template or render function
cause Route component name not registered as a Vue component.
fix
Ensure the component string matches a registered Vue component (e.g., via .js file or trame's component decorator).
breaking In version 2.0.0, the import path changed from 'trame_router' to 'trame_router.widgets'. Old imports will break.
fix Update imports: from trame_router.widgets import RouterView, RouterLink
gotcha Routes must be defined in server.state['routes'] and components must be registered as strings (names of Vue components). Defining components inline in Python does not work.
fix Create Vue components in separate .js files or use trame's component registration.

Basic setup for a trame app with Vue Router.

from trame.app import get_server
from trame_router.widgets import RouterView, RouterLink
server = get_server()
server.state['routes'] = [
    {'path': '/', 'component': 'Home'},
    {'path': '/about', 'component': 'About'}
]
@server.expose
def navigate():
    server.state.trame__router = '/about'
with server.layout as layout:
    layout.add_child(RouterLink(to="/about", label="About"))
    layout.add_child(RouterView())
server.start()