gpt4 book ai didi

javascript - Meteor - 简单的 react 路由器抛出错误

转载 作者:行者123 更新时间:2023-11-30 09:37:18 24 4
gpt4 key购买 nike

我基本上是直接从文档中复制代码,但它抛出了一个奇怪的错误。

 Warning: Failed prop type: The prop `history` is marked as required in
`Router`, but its value is `undefined`.
in Router

这是我的代码:

client/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'))
})

imports/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>
)

imports/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} 设置了

最佳答案

React Docs 切换到示例,

imports/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>
)

关于javascript - Meteor - 简单的 react 路由器抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42800106/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com