Skip to content

Commit 7b12bf6

Browse files
committed
Move warnings from render => cWM
1 parent 1f9f61b commit 7b12bf6

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

packages/react-router-dom/modules/BrowserRouter.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ class BrowserRouter extends React.Component {
1818

1919
history = createHistory(this.props)
2020

21-
render() {
21+
componentWillMount() {
2222
warning(
2323
!this.props.history,
2424
'<BrowserRouter> ignores the history prop. To use a custom history, ' +
25-
'make sure you are using `import { Router }` and not `import { BrowserRouter as Router }`.'
25+
'use `import { Router }` instead of `import { BrowserRouter as Router }`.'
2626
)
27+
}
2728

29+
render() {
2830
return <Router history={this.history} children={this.props.children}/>
2931
}
3032
}

packages/react-router-dom/modules/HashRouter.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ class HashRouter extends React.Component {
1717

1818
history = createHistory(this.props)
1919

20-
render() {
20+
componentWillMount() {
2121
warning(
2222
!this.props.history,
2323
'<HashRouter> ignores the history prop. To use a custom history, ' +
24-
'make sure you are using `import { Router }` and not `import { HashRouter as Router }`.'
24+
'use `import { Router }` instead of `import { HashRouter as Router }`.'
2525
)
26+
}
2627

28+
render() {
2729
return <Router history={this.history} children={this.props.children}/>
2830
}
2931
}

packages/react-router/modules/MemoryRouter.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ class MemoryRouter extends React.Component {
1818

1919
history = createHistory(this.props)
2020

21-
render() {
21+
componentWillMount() {
2222
warning(
2323
!this.props.history,
2424
'<MemoryRouter> ignores the history prop. To use a custom history, ' +
25-
'make sure you are using `import { Router }` and not `import { MemoryRouter as Router }`.'
25+
'use `import { Router }` instead of `import { MemoryRouter as Router }`.'
2626
)
27+
}
2728

29+
render() {
2830
return <Router history={this.history} children={this.props.children}/>
2931
}
3032
}

packages/react-router/modules/StaticRouter.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ class StaticRouter extends React.Component {
112112
handleBlock = () =>
113113
noop
114114

115+
componentWillMount() {
116+
warning(
117+
!this.props.history,
118+
'<StaticRouter> ignores the history prop. To use a custom history, ' +
119+
'use `import { Router }` instead of `import { StaticRouter as Router }`.'
120+
)
121+
}
122+
115123
render() {
116124
const { basename, context, location, ...props } = this.props
117125

@@ -128,12 +136,6 @@ class StaticRouter extends React.Component {
128136
block: this.handleBlock
129137
}
130138

131-
warning(
132-
!this.props.history,
133-
'<StaticRouter> ignores the history prop. To use a custom history, ' +
134-
'make sure you are using `import { Router }` and not `import { StaticRouter as Router }`.'
135-
)
136-
137139
return <Router {...props} history={history}/>
138140
}
139141
}

0 commit comments

Comments
 (0)