Starting from GenUI v0.1.2, the framework has introduced the routing configuration function. However, it should be noted that GenUI's routing mechanism is different from the "front-end routing" in traditional Web front-ends. There is no real URL routing in GUI applications. GenUI's routing is essentially a page switching mechanism for state management and navigation between multiple UI interfaces.
GenUI's routing mechanism is based on a dedicated component and is enabled through the project configuration file. You can declare the routing structure in router.toml
, enable the configuration in gen_ui.toml
, and then introduce it to a specific page through the route!
macro.
For more examples, see:
router.toml
You can define a complete route configuration through router.toml
, including route mode, default activation page, whether to enable Tabbar, page path, etc.:
gen_ui.toml
In the .gen
file where routing is needed, use the route!
macro to import the declared routing component:
If the route!
macro is used, the .gen
file cannot contain other elements and must be used only for routing.
You can embed the Router component in other pages just like using a normal component:
If you want to use the Router component as the root component of your application, use the route!
macro in the root.gen
file.
At this time,
name
inrouter.toml
must be set to"UiRoot"
to ensure that the compiler recognizes it as the main entry.
You can get the router instance through the c_ref!
macro and call the method it provides:
For child components, GenUI provides convenient macros nav_to!
and nav_back!
to handle jumps:
Key | Type | Description |
---|---|---|
name | String | Routing component name |
id | String | Routing component unique identifier |
mode | NavMode | Routing mode, supports History (history stack) and Switch (switch mode) |
active | Option<String> | Default activated page ID |
tabbar | Option<TabbarBuilder> | Tabbar configuration items (optional) |
bar_pages | Vec<(String, Page)> | Primary page configuration, supports component specification |
nav_pages | HashMap<String, Page> | Secondary page configuration, not displayed in Tabbar |
TabbarItem.icon | Option<LiveDependency> | Icon resource path |
TabbarItem.text | Option<String> | Tabbar display text |