2016-03-03 99 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