cli icon indicating copy to clipboard operation
cli copied to clipboard

Generate static routes

Open maccesch opened this issue 3 years ago • 8 comments

Reading routes from dioxus' Router would be nice. These routes should then be generated as static html files when executing dioxus build for a web app.

So a

Link {
    to: "/foo/bar",
}

would generate dist/foo/bar/index.html.

This is what nuxt generate does for example.

Additionally (or maybe as an easier first step) there should be an option in Dioxus.toml what routes are generated.

maccesch avatar Apr 28 '22 02:04 maccesch

so we need check route info and generate the file ?

mrxiaozhuox avatar Apr 29 '22 00:04 mrxiaozhuox

but the router is manage with dioxus-router, so we cannot know what we need generate.

mrxiaozhuox avatar Apr 29 '22 00:04 mrxiaozhuox

Reading routes from dioxus' Router would be nice. These routes should then be generated as static html files when executing dioxus build for a web app.

So a

Link {
    to: "/foo/bar",
}

would generate dist/foo/bar/index.html.

This is what nuxt generate does for example.

Additionally (or maybe as an easier first step) there should be an option in Dioxus.toml what routes are generated.

I actually really like this concept - we could allow a hardcoded list or just look around for the Router component and parse out the contents.

jkelleyrtp avatar Apr 29 '22 00:04 jkelleyrtp

Reading routes from dioxus' Router would be nice. These routes should then be generated as static html files when executing dioxus build for a web app. So a

Link {
    to: "/foo/bar",
}

would generate dist/foo/bar/index.html. This is what nuxt generate does for example. Additionally (or maybe as an easier first step) there should be an option in Dioxus.toml what routes are generated.

I actually really like this concept - we could allow a hardcoded list or just look around for the Router component and parse out the contents.

but how can we generate the xxx/index.html file

mrxiaozhuox avatar Apr 29 '22 00:04 mrxiaozhuox

Reading routes from dioxus' Router would be nice. These routes should then be generated as static html files when executing dioxus build for a web app. So a

Link {
    to: "/foo/bar",
}

would generate dist/foo/bar/index.html. This is what nuxt generate does for example. Additionally (or maybe as an easier first step) there should be an option in Dioxus.toml what routes are generated.

I actually really like this concept - we could allow a hardcoded list or just look around for the Router component and parse out the contents.

but how can we generate the xxx/index.html file

A "dumb" way would be to spin up a local dev server and scrape it once the page loaded. A more sophisticated way would be to have an "SSR" entry point in your code (alongside other potential entrypoints) that gets called with some environment-driven context.

fn main_web() {
    dioxus::web::launch(app);
}

fn main_ssr() {
    dioxus::ssr::static_gen(app) // prints to stdout
}

jkelleyrtp avatar Apr 29 '22 00:04 jkelleyrtp

use dioxus::ssr::static_gen for each page components ?

mrxiaozhuox avatar Apr 29 '22 00:04 mrxiaozhuox

We don't have a static_gen function yet but I could imagine it would pull from environment variables or stdin or IPC and be commanded by the CLI to generate each page.

jkelleyrtp avatar Apr 29 '22 00:04 jkelleyrtp

We need to allow the CLI to interact with the program.

mrxiaozhuox avatar Apr 29 '22 00:04 mrxiaozhuox