Reactjs 仅在具有道具的路由上作出反应而不进行api调用
在我的应用程序中,有一个标题导入到组件顶部,其中包含3个链接下拉列表。在我的网站上的任何地方,这些下拉菜单都能正常工作,只有一个下拉菜单在我将道具id传递给路由器的页面上不起作用 发生问题的路线:Reactjs 仅在具有道具的路由上作出反应而不进行api调用,reactjs,react-router,Reactjs,React Router,在我的应用程序中,有一个标题导入到组件顶部,其中包含3个链接下拉列表。在我的网站上的任何地方,这些下拉菜单都能正常工作,只有一个下拉菜单在我将道具id传递给路由器的页面上不起作用 发生问题的路线: <Route path="/service/:name" render={(props) => <ServiceShow {...props} />}/> <Route path="/employee/:userId" re
<Route path="/service/:name" render={(props) => <ServiceShow {...props} />}/>
<Route path="/employee/:userId" render={(props) => <EmployeeShow {...props} />}/>
<Route path="/class/:id" render={(props) => <ClassShow {...props} />}/>
componentWillMount()
已弃用。很遗憾,这并没有解决问题。我看不出您在哪里调用this.props.id。这个下拉列表也是一个HOC吗?您是否可以包括不工作的路由如何调用下拉列表?“…下拉列表工作,但在我向路由器传递属性id的页面上有一个下拉列表不工作”。您的代码片段中有哪些下拉列表?路由器在哪里?请包括所有相关代码。
componentWillMount() {
this.fetchEmployees()
this.fetchCategories()
this.fetchClasses()
}
fetchCategories = async() => {
const response = await fetch(`/api/categories`)
const initialCategories = await response.json()
const services = initialCategories
this.setState({
services
})
}
fetchClasses = async() => {
console.log("^^^^^^^^^^^^^^1Clases IN HEADER")
const response = await fetch(`/api/classes`)
const initialClass = await response.json()
const classes = initialClass
console.log("^^^^^^^^^^^^^^Clases IN HEADER", classes)
this.setState({
classes
})
}
fetchEmployees = async() => {
console.log("^^^^^^^^^^^^^^1Employee IN HEADER")
const response = await fetch(`employees`)
console.log("^^^^^^^^^^^^^^2Employee IN HEADER", response)
const initialUser1 = await response.json()
console.log("^^^^^^^^^^^^^^3EMPLYEES IN HEADER", initialUser1)
const employees1 = initialUser1
console.log("^^^^^^^^^^^^^^EMPLYEES IN HEADER", employees1)
this.setState({
employees: employees1
})
}