angular / router

The Angular 1 Component Router
MIT License
666 stars 135 forks source link

Common views duplicated among components #282

Open ns6482 opened 9 years ago

ns6482 commented 9 years ago

I want to create a common template project, that has the typical header, footer navigation etc. So you can imagine routes defined like this...

 AppController.$routeConfig = [{
        path: '/',
        components: {
            'headerView': 'header',
            'navigationView': 'navigation',
            'mainView': 'home',
            'footerView': 'footer'
        }
    }, {
        path: '/detail/:id',
        components: {
            'headerView': 'header',
            'navigationView': 'navigation',
            'mainView': 'detail',
            'footerView': 'footer'
        }
    }];

How can I avoid duplicating the components in the path. Is it possible to set it generically. If you can imagine I want to create an equivalent to rail's layout, yield, or .net's master page.

nextor2k commented 9 years ago

Maybe something like this:

function defaultComponents(mainView) {
    var components = {
        'headerView': 'header',
        'navigationView': 'navigation',
        'mainView': '',
        'footerView': 'footer'
    };
    components.mainView = mainView;
    return components;
}

AppController.$routeConfig = [{
    path: '/',
    components: defaultComponents('home')
}, {
    path: '/detail/:id',
    components: defaultComponents('detail')
}];
ns6482 commented 9 years ago

That would workm. Thanks

corydorning commented 9 years ago

While this works, it didn't seem scalable...

Sent from my iPhone

On Apr 24, 2015, at 3:03 PM, Nehal Soni notifications@github.com wrote:

That would workm. Thanks

— Reply to this email directly or view it on GitHub.

ns6482 commented 9 years ago

Not sure I understand why, If this was a common module, could you expose the function via a service

corydorning commented 9 years ago

For instance, if you have 3 common routes (views?) Header, nav, footer and 10 others (or more as nested views could have additional views) it would be nice to set only those that you want changed instead of passing a loaded object to a reusable function that returns your components object.

On my phone so hard to outline and example so hopefully this makes sense. If not I'll try to mock something up as soon as I can.

Sent from my iPhone

On Apr 24, 2015, at 3:09 PM, Nehal Soni notifications@github.com wrote:

Not sure I understand why, If this was a common module, could you expose the function via a service

— Reply to this email directly or view it on GitHub.

darcnite3000 commented 9 years ago

Question: would using an es6 extends work here?