2016-03-03 45 views
0
  • 我已经使用react创建了一些组件。现在我需要在index.html页面上呈现 这些组件,当我点击index.html页面上的菜单栏 选项时。下面菜单项创建在index.html页面渲染组件

    1.On index.html页面: enter image description here

  • 我已创建home.jsservice.jsabout.js,contactUs.js组件。 现在我需要当我点击首页选项,然后渲染 home.js,当我点击关于选项渲染about.js。

回答

1

这听起来像你可能需要一个路由解决方案,让你看了一眼阵营,路由器React-Router

1

创建路径使用阵营路由器需要 例如在routes.js定义路线为您的应用

module.exports = (
     <Route path="/" component={App}> 
      <IndexRoute component={Home}/> 
      <Route path="/services" component={Services}/> 
      <Route path="/about" component={About}/> 
      <Route path="/contact" component={ContactUs}/> 
     </Route> 
) 

创建的切入点,你的应用可以说index.js

import React from 'react'; 
import ReactDOM from 'react-dom'; 
import {Router,browserHistory} from 'react-router'; 
import routes from './routes'; 

ReactDOM.render(
    <Router routes={routes} history={browserHistory}/> 
    , document.querySelector('.init') 
); 

这将使反应组件.init格或任何你的名字在你的index.html

+0

@A Jain你能解决你的问题吗? – WitVault