Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot reproduce routing examples from documentation, get an error #980

Open
tdard opened this issue Jan 21, 2025 · 1 comment
Open

Cannot reproduce routing examples from documentation, get an error #980

tdard opened this issue Jan 21, 2025 · 1 comment

Comments

@tdard
Copy link

tdard commented Jan 21, 2025

Hi, I was trying to reproduce the examples given in here and I obtain the following error: Page not found: /, route does not link to a (markdown) path or module or component

It seems that using a route without a component is not supported. Is that true ? I read all the unit tests in relation to routing and no one tests the use case where the Route(path"/") does not have a component.

Here is the code that I wrote:

import solara

routes = [
    solara.Route(path="/"),
    solara.Route(path="kiwi"),
    solara.Route(path="banana"),
    solara.Route(path="apple"),
]


@solara.component
def Page():
    route_current, routes = solara.use_route()

    solara.Markdown("*Click on one of the links below to change the route and see the url in your browser change, and match the route.*")
    with solara.VBox():
        for route in routes:
            with solara.Link(route):
                current = route_current is route
                if current:
                    solara.Success(f"You are at solara.Route(path={route.path!r})")
                else:
                    solara.Info(f"Go to solara.Route(path={route.path!r})")

I use solara 1.41.0 on MacOS.

Thank you by advance,

T.

@iisakkirotko
Copy link
Collaborator

Hi @tdard! Sorry for taking a while to reply - we've had a pretty busy time.

We can get away with not providing a component to the path "/" since the page in question is not the starting point of our execution. Rather, when running the documentation website, we run a parent module of the file in question - to run the documentation website locally, you can use solara run solara.website.pages. This gets the corresponding module from the package solara and executes it, rather than just running a python file. Running a module means that we automatically discover server paths and pick up Page and Layout components from those paths. Since we don't provide a component argument to the routes we defined manually, the one in it's parent file is used automatically. The docs page on understanding routing has some more information.

If you want to play around with / see this in action, I made a minimal example in this repo. If you have any follow up questions, feel free to ask!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants