这是我的html
文件:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style/style.css">
</head>
<body>
<button id="aa">another</button>
<button id="eng">English</button>
<div class="container"></div>
<div class="containerAA"></div>
</body>
<script src="bundle.js"></script>
<script src="index.js"></script>
<script src="indexAr.js"></script>
</html>
我希望在click
(另一个)button
上为class
容器提供div render
functions
来自indexAr.js
,
当click
button
(英文)时,它会给class
containerAA div
这是来自render
的{{1}}数据。
答案 0 :(得分:0)
我认为当您使用React router
并保留单个index.js
文件时,可以更轻松地解决问题。您无需单独捆绑文件。
您的路线将在index.js中,并且看起来像
import {Router, hashHistory, Route} from 'react-router'
ReactDOM.render(
<Router history={hashHistory}>
<Route path="/" component={App}>
<Route path="another" component={Another}/>
<Route path="english" component={English}/>
</Route>
</Router>, document.getElementById('app')
)
你的应用程序组件将类似
import {Link} from 'react-router';
class App extends React.Component {
render() {
return (
<div>
<button><Link to="another">Another</Link><button>
<button><Link to="english">English</Link></button>
<div>{this.props.children}</div>
</div>
)
}
}
我认为对于你想要实现的目标,这是一种更好的反应方式。
您可以按照以下 youtube tutorial 来设置您的react-router