-
Notifications
You must be signed in to change notification settings - Fork 0
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
Router #4
Comments
Here’s React Router. Had to do some research with ChatGPT because there are too many breaking changes across the years. I like using JSX children. Most development after React Router v4 seems to be about working around React limitations and chasing after hooks insanity. ChatGPT:
I sincerely do not understand the marginal differences between Edit: |
Okay. Here are my latest cogitations on a router API. const routes = <>
<Route path="/">
<HomeView />
</Route>
<Route path="/blog">
<BlogHomeView />
</Route>
<Route path="/blog/:slug">
<BlogView />
</Route>
<Route path="/guides/:slug">
<GuideView />
</Route>
<Route path="/playground">
<PlaygroundView />
</Route>
</>; With the jsx template tag: const routes = jsx`
<${Route} path="/">
<${HomeView} />
<//Route>
<${Route} path="/blog">
<${BlogHomeView} />
<//Route>
<${Route} path="/blog/:slug">
<${BlogView} />
<//Route>
<${Route} path="/guides/:slug">
<${GuideView} />
<//Route>
<${Route} path="/playground">
<${PlaygroundView} />
<//Route>
`; The real value of routes as JSX is when you have nested routes. const routes = <>
<Route path="/">
<HomeView />
</Route>
<Route path="/blog">
<BlogNavbar />
<BlogSidebar />
<Route path="">
<BlogHomeView />
</Route>
<Route path="/:slug">
<BlogView />
</Route>
</Route>
</>; Routes can be nested arbitrarily. Should probably have Some things I’ve been thinking about:
|
Some more thoughts, less coherent: One thing I don’t like about context-style APIs, is that I often want to pull the data directly from the Route, somehow, like when I see: <Route path="/:slug">
<BlogView />
</Route> I want to be able to inline the This is a struggle I have when working with Provider-style APIs in general, not really specific to . Another thing, how do routes actually work with the whole HTML thing? One feature I really want with shovel is to put the rendering of the entire HTML page in user-space. In other words, there shouldn’t be some hidden abstraction for the layout of pages, it should just be identifiable from the rendering of the response, jump to definition, everything from There are three solutions: Option 1: <Route path=":slug">
<ComponentIncludingHeadandBody />
</Route> Put the entire document in the route children. This works, and is accurate but subjectively feels dumb. It reduces the flexibility of putting routes in JSX, and if this is the only solution then maybe there’s something to be said about not going down the routes in JSX path. Path information can be extracted with providers/consumers, but is that all we get? Option 2: <head>
<HelmetMeta />
</head>
<Route path=":slug">
{/* In some component or code */}
<Helmet title={title} />
</Route> The react-helmet solution. I’m not really a big fan of this sorta abstraction. Kinda confusing to have route-dependent rendering outside of a route, debugging heads is kinda hard because you have to search the entire application tree, and it’s a pain in the ass to implement, likely you’ll need a double render. Option 3: <head>
{/* head stuff */}
<Route path="blog">
<Route path="/:slug">
<BlogHead />
</Route>
</Route>
</head>
<body>
<Route path="blog">
<BlogView />
</Route>
</body> ME NO LIKE TO DEFINE ROUTE TREE TWICE. Honestly, some version of Option 1 will likely have to suffice. I guess I am still struggling with why routing needs to go into JSX. The apps nested in paths and dashboards and stuff is cool but I am sweating the details now. |
Okay. Some new-ish thoughts about routing My hate for file-system routing persistsWhy? So many reasons!
In short, I think that it’s essential for routing abstractions to be obvious and readable, and putting this crucial data in the filesystem is both a rough developer experience. React Router style routingThe same sorts of objections hold with putting route configuration in JSX element trees. Nesting and reuse of layouts can be done with code reuse in the various handlers, non-linear matching is again a problem, and the route definitions are hard to read because of their nesting and all the noise.
|
See #3 for context about the broader project.
I want a router. Here are some popular styles for routers out there. We will not be considering file-system based routing options.
Express.js
Things I like:
path-to-regexp
Things I don’t like:
get()
for responses which do HTML. That feels like it should be separate.Vue Router
Vue Router seems to inject params and other routing data with a special
$route
. Child routing, with automatic component nesting. Could be nice but again is pretty framework specific.Things I like.
Things I don’t like
Django
Here’s the nesting concept:
Where it all started for me. Honestly, I just want to port this.
I like:
path-to-regexp
has an alternative.I don’t like:
include()
is for managing a lot of paths for a larger application.CLEARLY, I am ambivalent about nested routing patterns.
The text was updated successfully, but these errors were encountered: