Skip to content
This repository has been archived by the owner on Jan 25, 2018. It is now read-only.

Nested Routes #14

Closed
AngeloYoun opened this issue Dec 1, 2016 · 5 comments
Closed

Nested Routes #14

AngeloYoun opened this issue Dec 1, 2016 · 5 comments

Comments

@AngeloYoun
Copy link

AngeloYoun commented Dec 1, 2016

It is a common use case where a site structure needs to have nested routing.

Currently, only the top level URL routes can be routed via metal-router. It would be useful to be able to do something along the lines of:

<Router component={SomeComponent} path={some/path/:param1} />

...

class SomeComponent extends JSXComponent {
    render() {
        return {
            <div class="wrapper">
                <HeaderComponent />

                <Router component={FooComponent} path={some/path/:param1/view1} />

                <Router component={BarComponent} path={some/path/:param1/view2} />
            </div>
        }
    }
}
@mthadley
Copy link

mthadley commented Dec 2, 2016

I always thought react-router had a nice API for this:

// Router Configuration
<Route path="/" component={App}>
    <Route path="about" component={About}/>
    <Route path="users" component={Users}>
        <Route path="/user/:userId" component={User}/>
    </Route>
    <Route path="*" component={NoMatch}/>
</Route>

// Resulting Component Trees...

// Route: /
<App/>

// Route: /about
<App>
    <About />
</App>

// Route: /user/23
<App>
    <Users>
        <User userId={23} />
    </Users>
</App>

// Route: /somerandomurl
<App>
    <NoMatch />
</App>

I'm not sure, but I think this layout can still be achieved with the current API. However I think there would be more boilerplate involved.

@bawachhe
Copy link

bawachhe commented Dec 2, 2016

That would be pretty useful for us in terms of code cleanliness as well, as we currently have something like this.

<Router component={CreateMain} path={`${PortletConstants.urls.basePath}/main/create`} />
<Router component={CreateMain} path={`${PortletConstants.urls.basePath}/main/create/:model([a-zA-Z]+)`} />
<Router component={EditMain} path={`${PortletConstants.urls.basePath}/main/:portletMainId(\\d+)`} />
<Router component={EditMain} path={`${PortletConstants.urls.basePath}/main/:portletMainId(\\d+)/:action([a-zA-Z]+)`} />
<Router component={EditMain} path={`${PortletConstants.urls.basePath}/main/:portletMainId(\\d+)/edit/:model([a-zA-Z]+)`} />
<Router component={EditMain} path={`${PortletConstants.urls.basePath}/main/:portletMainId(\\d+)/edit/:model([a-zA-Z]+)/:action([a-zA-Z]+)`} />
<Router component={EditMain} path={`${PortletConstants.urls.basePath}/main/:portletMainId(\\d+)/edit/:model([a-zA-Z]+)/:entryId(\\d+)`} />
<Router component={EditMain} path={`${PortletConstants.urls.basePath}/main/:portletMainId(\\d+)/edit/:model([a-zA-Z]+)/:entryId(\\d+)/:action([a-zA-Z]+)`} />
<Router component={Index} path={this._defaultRoute} />

@mairatma
Copy link
Contributor

mairatma commented Dec 2, 2016

Agreed, this would be a really nice feature.

@robframpton
Copy link
Contributor

Just an update on this, I have a branch with this working, just waiting on #25 to get merged first.

@jbalsas
Copy link
Contributor

jbalsas commented Jan 24, 2018

Moved to metal/metal-plugins#12

@jbalsas jbalsas closed this as completed Jan 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants