DioxusLabs / DioxusLabs/dioxus

Change dioxus_router to require explicitly setting components to be used

Open
#3,973 8 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

## Feature Request

The current implementation of the Routable macro pulls in components from the namespace by default.

However this can make it quite unclear what is being used and forces users to keep names consistent between the components and routers.

This can also mess with people ide's workflows, as many people (myself included) have binds for going to the definition of something or renaming all instances of a identity.

```rust
#[rustfmt::skip]
#[derive(Clone, Debug, PartialEq, Routable)]
enum Route {
#[nest("/blog")]
#[layout(Blog)]
#[route("/")]
BlogList {},

#[route("/:blog_id")]
BlogPost { blog_id: usize },
#[end_layout]
#[end_nest]
#[route("/")]
Index {},
}
```

## Implement Suggestion

Force the explicit use of components in for each route of the router instead of implicitly finding them in the namespace, in order to make it clearer what's being used and to stop namespace collisions.

```rust
#[rustfmt::skip]
#[derive(Clone, Debug, PartialEq, Routable)]
enum Route {
#[nest("/blog")]
#[layout(Blog)]
#[route("/", BlogList)]
BlogList {},

#[route("/:blog_id", BlogPost)]
BlogPost { blog_id: usize },
#[end_layout]
#[end_nest]
#[route("/", Home)]
Index {},
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Routable macro implementation and trace how route attributes currently find components from the namespace. Compare that behavior with the explicit component arguments shown in the examples; done means each route names its component explicitly and namespace collisions are no longer used for lookup.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.