I’m continuing the discussion here, because this post is long, and the forum works better for that than chat…
So what I’d want to be able to express is something like this
<Router>
<MainLayout>
<AdminContextProvider>
<AdminLayout>
<Private unauthenticated="home">
<Route path="/admin/posts/new" page={NewPostPage} name="newPost" />
<Route path="/admin/posts/{id:Int}/edit" page={EditPostPage} name="editPost" />
<Route path="/admin/posts/{id:Int}" page={PostPage} name="post" />
<Route path="/admin/posts" page={PostsPage} name="posts" />
</Private>
</AdminLayout>
</AdminContextProvider>
<FooBarBazContextProvider>
<Route path="/foo" page={FooPage} name="foo" />
<Route path="/bar" page={BarPage} name="bar" />
<BarWizardContextProvider>
<WizardLayout>
<TransitionGroup>
<CSSTransition>
<Route path="/bar/wizard/step1" page={BarWizOnePage} name="barWizOne" />
<Route path="/bar/wizard/step2" page={BarWizTwoPage} name="barWizTwo" />
<Route path="/bar/wizard/step3" page={BarWizThreePage} name="barWizThree" />
<Route path="/bar/wizard/step4" page={BarWizFourPage} name="barWizFour" />
</CSSTransition>
</TransitionGroup>
</WizardLayout>
</BarWizardContextProvider>
<Route path="/baz" page={BazPage} name="baz" />
<BazWizardContextProvider>
<WizardLayout>
<TransitionGroup>
<CSSTransition>
<Route path="/baz/wizard/step1" page={BazWizOnePage} name="bazWizOne" />
<Route path="/baz/wizard/step2" page={BazWizTwoPage} name="bazWizTwo" />
<Route path="/baz/wizard/step3" page={BazWizThreePage} name="bazWizThree" />
</CSSTransition>
</TransitionGroup>
</WizardLayout>
</BazWizardContextProvider>
</FooBarBazContextProvider>
<Route path="/" page={HomePage} name="home" />
<Route path="/about" page={AboutPage} name="about" />
<Route notfound page={NotFoundPage} />
</MainLayout>
</Router>
What I don’t like about that though is that it clutters my router and makes it harder to get that nice “site map” thing going that I get with the way the router currently looks. And also, context providers really doesn’t have anything to do with routing, and neither do transition groups, so maybe shouldn’t be here because of that reason. Same thing could maybe be said about the layouts as well.
So, from that example above, what I would really like to look at is this:
<Router>
<PrivateRoute path="/admin/posts/new" page={NewPostPage} name="newPost" />
<PrivateRoute path="/admin/posts/{id:Int}/edit" page={EditPostPage} name="editPost" />
<PrivateRoute path="/admin/posts/{id:Int}" page={PostPage} name="post" />
<PrivateRoute path="/admin/posts" page={PostsPage} name="posts" />
<Route path="/foo" page={FooPage} name="foo" />
<Route path="/bar" page={BarPage} name="bar" />
<Route path="/bar/wizard/step1" page={BarWizOnePage} name="barWizOne" />
<Route path="/bar/wizard/step2" page={BarWizTwoPage} name="barWizTwo" />
<Route path="/bar/wizard/step3" page={BarWizThreePage} name="barWizThree" />
<Route path="/bar/wizard/step4" page={BarWizFourPage} name="barWizFour" />
<Route path="/baz" page={BazPage} name="baz" />
<Route path="/baz/wizard/step1" page={BazWizOnePage} name="bazWizOne" />
<Route path="/baz/wizard/step2" page={BazWizTwoPage} name="bazWizTwo" />
<Route path="/baz/wizard/step3" page={BazWizThreePage} name="bazWizThree" />
<Route path="/" page={HomePage} name="home" />
<Route path="/about" page={AboutPage} name="about" />
<NotFoundRoute page={NotFoundPage} />
</Router>
I don’t have a good solution for how to solve this. But I do have some crazy ideas
- Ask @aldonline if it’s possible to make the Redwood VS Code plugin show/hide the extra elements (layout, providers… everything except the routes), so you can choose if you want to see the full thing, or just the routes
- Introduce a
config
object to the router{ unauthenticated: "home", layouts: { // some way to specify what layouts wrap what pages }, contextProviders: { // same idea as layouts pretty much } }
- Specify the layouts and context providers separately from the router
This would all just be synthetically. We would have to transpile the file to look like my big<Layouts> <MainLayout pages="foo, bar, home, about, notfoundpage"> <AdminLayout pages="newPost, editPost, post, posts" /> <WizardLayout pages="barWizOne, barWizTwo, barWizThree, barWizFour" /> <WizardLayout pages="bazWizOne, bazWizTwo, bazWizThree" /> </MainLayout> </Layouts> <Providers> <AdminContextProvider pages="newPost, editPost, post, posts" /> <FooBarBazContextProvider pages="foo, bar, barWizOne, barWizTwo, barWizThree, barWizFour, bazWizOne, bazWizTwo, bazWizThree" /> <BarWizardContextProvider pages="barWizOne, barWizTwo, barWizThree, barWizFour" /> <BazWizardContextProvider pages="bazWizOne, bazWizTwo, bazWizThree" /> </Providers>
<Router>
example up top.
I’m not thrilled about any of the options, so very open to other ideas. And I haven’t mentioned transitions. But I think those could go inside a layout.
Basically, I’m asking, “How do we bridge the gap between “needed” and “wanted””?