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

feat: support modifyRouteProps in runtime #1324

Merged
merged 1 commit into from
Oct 25, 2018

Conversation

sorrycc
Copy link
Member

@sorrycc sorrycc commented Oct 25, 2018

想到的一些使用场景,这些场景之前用 Routes 也能做,但比较繁琐,而且会多套一层 react 组件。

比如想要访问子路径匹配路由的 match.params 属性,可以在 app.js 下配置,

例子,sorrycc-aRg4p8.zip

import { matchRoutes } from 'react-router-config';

export function modifyRouteProps(memo, { route }) {
  if (/* is layout */route.routes) {
    const m = matchRoutes(route.routes, memo.location.pathname);
    if (m && m.length) {
      memo.match = m[m.length - 1].match;
    }
  }

  return memo;
}

比如实现 title 的 i18n

可以在这一层针对 title 做运行时的转换。

@coveralls
Copy link

Pull Request Test Coverage Report for Build 1760

  • 2 of 2 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 34.965%

Totals Coverage Status
Change from base Build 1757: 0.01%
Covered Lines: 1038
Relevant Lines: 3058

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants