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

Meta attributes inside Route? #927

Closed
mikechau opened this issue Mar 8, 2015 · 6 comments
Closed

Meta attributes inside Route? #927

mikechau opened this issue Mar 8, 2015 · 6 comments

Comments

@mikechau
Copy link

mikechau commented Mar 8, 2015

I'm building breadcrumbs for my application and I think it would be really helpful for a Route to have a sort of meta property, where you could give it whatever attributes you want.

For example:

<Route name="profiles" path="/profiles" meta={{ breadcrumbName: 'Company Directory', icon: 'phonebook' }} />

Then you could just iterate over this.getRoutes() and do whatever you need to do. I think it would be much more convinent for simple cases then maintaining a seperate store that has mappings for each route by name. Or is using a store with a mapping to the route names preferred?
#492 @irvinebroque

@agundermann
Copy link
Contributor

Using a (global, immutable) name-props mapping is probably what I would do.

If you don't plan on using handlers for multiple routes, you could also consider putting those props on the handler statics and then do routes[0].handler.myProp. Finally, you could also wrap your handlers in a function as suggested in the Upgrade Guide.

There's another discussion about this in #615.

@malte-wessel
Copy link

+1

@malte-wessel
Copy link

I made a PR: #1002

@ryanflorence
Copy link
Member

You can put that meta data on your handlers:

<Route name="profiles" path="/profiles" handler={Profiles} />

class Profiles extends React.Component {
  render () {
    var { icon } = this.constructor.breadcrumbs;
  }
}

Profiles.breadcrumbs = {
  breadcrumbName: 'Company Directory',
  icon: 'phonebook'
};

@ryanflorence
Copy link
Member

oh, sorry @taurose I jumped straight to the comment box and missed yours!

@ivan-kleshnin
Copy link

You can put that meta data on your handlers

Most HOC builders entirely block access to original component, therefore to her static props.
We really need to reopen this issue. Everything is screwed by HOC: your data load example, ability to pass metadata etc. As the absolute minimum <Route /> should keep passed props and provide access to them within router.run.

@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

5 participants