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

Rename Switch trait #1107

Closed
hgzimmerman opened this issue Dec 17, 2019 · 2 comments · Fixed by #1791
Closed

Rename Switch trait #1107

hgzimmerman opened this issue Dec 17, 2019 · 2 comments · Fixed by #1791
Labels

Comments

@hgzimmerman
Copy link
Member

Description

While Switch is an ok name for what it does, I think something along the lines of Routable would be more appropriate.

I don't intend to make this change for 8.0, but would like to create this issue so that interested parties can prepare their codebase for this change.


This change will come in 3 pieces.

  1. Add Routable alias (0.8.0)
  2. Rewrite macro & Trait to use Routable instead, deprecate Switch, make Switch an alias to Routable (0.9.0)
  3. Remove Switch (0.10.0)
@Boscop
Copy link

Boscop commented Jan 25, 2020

@hgzimmerman Also, I think it would make much more sense to name the to attribute at instead:

#[derive(Switch, Debug)]
pub enum AppRoute {
    #[at = "/profile/{id}"]
    Profile(u32),
    #[at = "/forum{*:rest}"]
    Forum(ForumRoute),
    #[at = "/"]
    Index,
}

#[derive(Switch, Debug)]
pub enum ForumRoute {
    #[at = "/{subforum}/{thread_slug}"]
    SubForumAndThread{subforum: String, thread_slug: String}
    #[at = "/{subforum}"]
    SubForum{subforum: String}
}

Because links/buttons route to somewhere (it's an action to follow a link) but the routes are defined at a certain url, and at also reflects the fact that it's declarative better.

@allan2
Copy link
Contributor

allan2 commented Apr 24, 2021

Routable seems more confusing IMO than Switch.

Other frameworks use essentially two parts for their router:

  1. a route matcher
  2. navigational component.

1. Route Matcher:

// React
 <Switch>
  <Route path="/about">
    <About />
  </Route>
</Switch>

// Vue
const router = new VueRouter({
  routes: [
    { path: '/about', component: About }
  ]
})

// Angular
const appRoutes: Routes = [
  {
    path: "about",
    component: AboutComponent
  },

React does use a parent <Switch> and a child <Route> for their route matcher.
Note the use of path here instead of at or to.

2. Navigational Component:

<!-- Vue -->
<router-link to="/about">About</router-link>

<!-- React Router  -->
<Link to="/about">About</Link>

to is only used in the navigational component.

Why I think Routable is not a good name
What is a routable anyway? It's not a word that we hear often.
It could be something that gets routed, something that does the routing, or maybe something in between. "Routable" can also suggest something that might be routed. The naming does not add clarity here.

I am perfectly happy with the Switch/Route combo that React Router uses. I RouteMatcher would be ok but RouteMatcher/Route isn't as nice.

My suggestions

  1. Keep the name of Switch.
  2. Use path instead of at or to.

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

Successfully merging a pull request may close this issue.

4 participants