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

feature for breadcrumb #1999

Closed
plandem opened this issue Jun 8, 2016 · 5 comments
Closed

feature for breadcrumb #1999

plandem opened this issue Jun 8, 2016 · 5 comments

Comments

@plandem
Copy link
Contributor

plandem commented Jun 8, 2016

add method to get title for route instead of using breadcrumbName.

Now it's using this code(Breadcrumb.js) to get title:

          if (!route.breadcrumbName) {
            return null;
          }
          var name = route.breadcrumbName.replace(/:(.*)/g, function (replacement, key) {
            return params[key] || replacement;
          });

What i need:

var name = this.titleRender(route, params);

where default titleRender is :

Breadcrumb.defaultProps = {
  titleRender: function titleRender(route, params) {
 if (!route.breadcrumbName) {
            return null;
          }

          var name = route.breadcrumbName.replace(/:(.*)/g, function (replacement, key) {
            return params[key] || replacement;
          });
  }  
}

Why do i need it?

  1. i'm using https://github.com/callum/redux-routing , but not react-router and i don't want to 'patch' routes to set breadcrumbName

  2. i need custom logic - for first item, i want to draw icon, for rest i want text, now i do it like this:

                    <Breadcrumb>
                        { path.map((route, i) => {
                            let title = (i === 0) ? <Icon type="home"/> : formatMessage(messages[route.path]);
                            return (i !== last_i)
                                ? <Breadcrumb.Item key={i} href={'#' + route.build(route.path, matched.params)}>{title}</Breadcrumb.Item>
                                : <Breadcrumb.Item key={i}>{title}</Breadcrumb.Item>
                        }) }
                    </Breadcrumb>

In that case i would replace it with:

<Breadcrumb routes={routes} titleRender={(route, params) => { 
if (route.path === 'index') 
   return <Icon type="home"/>
else 
   return formatMessage(messages[route.path]);
}
}>
@plandem
Copy link
Contributor Author

plandem commented Jun 8, 2016

i can make a pull request, if you want

@afc163
Copy link
Member

afc163 commented Jun 9, 2016

I like it, you can pr for that, and please keep downward compatibility of breadcrumbName.

@plandem
Copy link
Contributor Author

plandem commented Jun 9, 2016

i will move current behaviour to default implementation for titleRender, so it will be backward compatible

@plandem
Copy link
Contributor Author

plandem commented Jun 10, 2016

now it can be used like this:

<Breadcrumb routes={path} params={matched.params} nameFormatter={(route, params)=> {
    if(route.path === ROUTE_TYPE.index) {
        return <Icon type="home"/>
    } else {
        return formatMessage(messages[route.path]);
    }
}}/>

@plandem plandem closed this as completed Jun 11, 2016
@lock
Copy link

lock bot commented May 5, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2018
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

2 participants