我基本上直接从文档中复制了代码,并且它抛出了一个特殊的错误。
Warning: Failed prop type: The prop `history` is marked as required in
`Router`, but its value is `undefined`.
in Router
这是我的代码:
的客户机/ main.jsx
import React from "react"
import { render } from "react-dom"
import { Meteor } from "meteor/meteor"
import { renderRoutes } from "../imports/ui/Routes.jsx"
Meteor.startup(() => {
render(renderRoutes(), document.getElementById('react-root'))
})
进口/ UI / Routes.jsx
import React from 'react'
import { render } from "react-dom"
import { Router, Route, IndexRoute, browserHistory } from 'react-router'
// route components
import App from "./App.jsx"
export const renderRoutes = () => (
<Router history={browserHistory}>
<Route path="/" component={App} />
</Router>
)
进口/ UI / App.jsx
import React, { Component } from 'react'
import TopBar from "./components/TopBar.jsx"
import LeftMenuContainer from "./components/LeftMenuContainer.jsx"
import LivePurchases from "./components/LivePurchases.jsx"
// App component - represents the whole app
export default class App extends Component {
render() {
return (
<div className="App">
<div className="flexWrapperGlobal">
<TopBar/>
<div className="contentContainer">
<LeftMenuContainer/>
<div className="bodyContainer">
<LivePurchases/>
<div className="siteContentContainer">
{this.props.children || "test"}
</div>
</div>
</div>
</div>
</div>
)
}
}
似乎不应该出现此错误,因为我在history={browserHistory}
设置道具
答案 0 :(得分:4)
切换到React Docs,
中的示例进口/ UI / Routes.jsx
import React from 'react'
import { render } from "react-dom"
import { Router, Route, IndexRoute } from 'react-router'
import createBrowserHistory from 'history/createBrowserHistory'
// route components
import App from "./App.jsx"
const history = createBrowserHistory()
export const renderRoutes = () => (
<Router history={history}>
<Route path="/" component={App} />
</Router>
)