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

Should we keep JSX configuration? #865

Closed
mjackson opened this issue Feb 23, 2015 · 13 comments
Closed

Should we keep JSX configuration? #865

mjackson opened this issue Feb 23, 2015 · 13 comments

Comments

@mjackson
Copy link
Member

I'm opening this issue to discuss whether or not we want to keep <Route name>. In c5a24a5 I introduced the Route class which lets you use a Route object directly in <Link to={MyRoute}>. This is nice when you have many, many routes that you can't keep all in one file.

Technically, this eliminates the need for <Route name> because you can just use object references. Indeed, I started the work on c5a24a5 excluding names altogether. However, when I went back to make the examples work with the new object reference style, it didn't feel nearly as convenient as just using a string name. I don't want people just getting started with the router to have to go through the ceremony of creating a bunch of object references, when a fairly high % of our users (arguably most) will get by just fine using only route names.

I can also understand people being bothered by the fact that there's more than one way to link to stuff. But it doesn't bother me enough to remove the feature entirely.

/cc @ryanflorence @taurose @josephsavona

mjackson referenced this issue Feb 23, 2015
[changed] Route names are nested

This commit formalizes and enhances two of the core primitives in
the router: Route and Match.

We get a few benefits from this:

1. Routes may now be created programmatically, as well as via JSX.
   This is useful in situations where it is desirable to assemble
   the route configuration using separate modules, instead of all
   at once. For example, in ApplicationRoute.js you could have:

    module.exports = Router.createRoute();

   and in UserProfileRoute.js:

    var ApplicationRoute = require('./ApplicationRoute');

    module.exports = Router.createRoute({
      parentRoute: ApplicationRoute,
      path: 'users/:id'
    });

2. <Link to> may reference a Route object directly.

    <Link to={UserProfileRoute}>

3. Route names may be re-used at different levels of the hierarchy.
   For example, you could have two different routes named "new" but
   nested inside different parent routes.

    <Route name="users" handler={Users}>
      <DefaultRoute handler={ShowAllUsers}/>
      <Route name="new" handler={NewUser}/>
    </Route>
    <Route name="posts" handler={Posts}>
      <DefaultRoute handler={ShowAllPosts}/>
      <Route name="new" handler={NewPost}/>
    </Route>

   Using this route configuration, you could <Link to="users.new"> or
   <Link to="posts.new"> depending on which one you wanted. A side
   effect of this is that names of nested routes are no longer "global",
   so e.g. <Link to="new"> won't work because it is ambiguous, but
   <Link to="posts"> will still work.
@rickharrison
Copy link

I really like having the ability to define all my routes in a single place with jsx. Both apps I have in production have around 40 routes, and I haven't felt any pain in maintaining a routes.jsx file with all of my definitions. I also like being able to just have a quick link as <Link to="foo-list">. I am in favor of keeping the name.

@mjackson mjackson changed the title Do we need <Route name>? Should we keep <Route name>? Feb 23, 2015
@ryanflorence
Copy link
Member

@rickharrison what if you just linked to the path? I find my route names end up just being truncated versions of the path, could conventionally say "foo/:id/bar/:name" becomes <Link to="foo.bar." params={params}/> where . just holds the place of dynamic segments?

@agundermann
Copy link
Contributor

Perhaps I'm missing something, but why drop <Route name> while keeping JSX configuration? Or is this about dropping JSX altogether? Without the name, we couldn't even generate links without using absolute URL paths, could we?

@ryanflorence
Copy link
Member

One benefit of getting rid of name is testing. If we supported these two ways to create a link:

<Link to="same/:path/as/:route/config" params={params}/>
<Link to={RouteObject} params={params}/>

Then we wouldn't need context at all to generate links. Any chance to not rely on context I'd love to take.

I also like how simple it is to <Link to="someName"/> though.

@mjackson
Copy link
Member Author

Without the name, we couldn't even generate links without using absolute URL paths, could we?

@taurose Great observation. Yes, that's correct. I preserved <Route name> for this reason.

@ryanflorence I'd rather not introduce yet another notation for paths. We already have URL patterns that have special notation. Another special notation is confusing, IMO.

@mjackson
Copy link
Member Author

we wouldn't need context at all to generate links

@ryanflorence Yes, that's a great point too and IMO the strongest argument in favor of not supporting string names. But I also think that @taurose has a great point: if we get rid of <Route name> we might as well get rid of JSX config altogether. <Route name> was always just a way to refer to a route without an actual reference to it.

@mjackson mjackson changed the title Should we keep <Route name>? Should we keep JSX configuration? Feb 24, 2015
@rickharrison
Copy link

@ryanflorence I don't like linking full paths all throughout the code base, because there have been instances where I change the URL for a particular resource. Then I just have to change it in one place and add a simple <RedirectRoute> to make sure the old url works.

For me, I just wouldn't want to add 40 more files to my project all for things which are just one line of configuration.

@mjackson
Copy link
Member Author

I just wouldn't want to add 40 more files to my project all for things which are just one line of configuration.

@rickharrison I hear you. That's exactly how I felt when I went to refactor all of our example apps to not use name. It felt tedious.

@ryanflorence
Copy link
Member

because there have been instances where I change the URL for a particular resource. Then I just have to change it in one place and add a simple to make sure the old url works.

Yeah, that was my original intent on name. Might as well keep it, @mjackson. I'd like to not build them up for people (I think your new code does parent.child with the name), because that removes the conveniences @rickharrison's mentions, and the reason I made name in the first place.

@ryanflorence
Copy link
Member

Just keep name as it works today, they're all just global references, don't concat with parents or anything.

@ryanflorence
Copy link
Member

whah what the heck, there are two issues here? all of these comments were for #865

@ryanflorence
Copy link
Member

wait, what is going on? why the topic change? keeping "name" and ditching "jsx" are different things.

@mjackson
Copy link
Member Author

@ryanflorence See @taurose' comment above #865 (comment)

@lock lock bot locked as resolved and limited conversation to collaborators Jan 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants