我正在对我从事的项目的代码进行一些更改。 我不得不禁止webpack插件设置baseURL,现在,当页面加载到index.jsx中时,才能使构造函数调用getResources并使getResources显式设置process.env.baseURL。我已经将getResources添加到main.jsx中,但是不确定index.jsx中的构造函数。如果有人对此有任何专业知识并可以提供帮助,那将是很好的。 我将在下面提供代码:
main.jsx
let baseURL = process.env.baseURL;
export function getResources() {
if (process.env.APP_SERVER_URL) {
baseURL = process.env.APP_SERVER_URL;
} else {
let urlPath = getHref() + '/api/v1/resources';
return request.get(urlPath).then(function (response) {
baseURL = response.data;
});
}
}
export default class IndexDisplay extends React.Component {
constructor() {
super();
this.state = { branchData: "",
displayComponent:"root",
templateData: []
}
}
componentWillMount() {
axios.get(baseURL + 'workflow')
.then(function (response) {
this.setState({
"templateData": ParseWorkflows(response.data)
},this.updateState)
}.bind(this));
}
..............
index.jsx
import React from 'react'
import ReactDOM from 'react-dom'
import {Router, Route, browserHistory, IndexRoute} from "react-router"
import WorkflowTemplateListDisplay
from'./template_list_view/workflowTemplateListDisplay.jsx'
import WorkflowTemplateByAgencyDisplay from
'./template_list_view/workflowTemplateByAgencyDisplay.jsx'
import WorkflowInstanceDisplay from
'./workflowInstanceView/workflowInstanceDisplay.jsx'
import GraphicalViewDisplay from
'./workflowGraphicalView/graphicalViewDisplay.jsx'
import WorkflowStepsTemplateDisplay
from'./templateStepsView/workflowStepsTemplateDisplay.jsx';
import WorkflowSearchByWorkflowIdDisplay from
'./searchByWorkflowID/workflowSearchByWorkflowIdDisplay.jsx'
import WorkflowTemplateMultiSearchDisplay from
'./template_list_view/workflowTemplateMultiSearchDisplay.jsx'
import TemplatesHierarchyTableDisplay from
'./template_list_view/components/TemplatesHierarchyTable.jsx'
import Main from './main.jsx'
ReactDOM.render((
<Router history={browserHistory}>
<Route path='/' component={Main}>
<IndexRoute component={WorkflowTemplateListDisplay}/>
<Route path='/workflowInstances' component={WorkflowInstanceDisplay}/>
<Route path='/workflowStepsTemplate' component={WorkflowStepsTemplateDisplay}/>
<Route path='/pictorialView' component={GraphicalViewDisplay}/>
<Route path='/workflowTemplateByAgency' component={WorkflowTemplateByAgencyDisplay}/>
<Route path='/searchByWorkflowID' component={WorkflowSearchByWorkflowIdDisplay}/>
<Route path='/search' component={WorkflowTemplateMultiSearchDisplay}/>
<Route path='/treeView' component={TemplatesHierarchyTableDisplay}/>
</Route>
</Router>), document.getElementById('app'));