2017-04-03 212 views
0

爲什麼只工作根路徑,當我到達本地主機:8090 /關於它 說的。無法獲得本地主機:8090 /約React路由器只適用於/路徑

import React,{Component} from "react" 
    import {BrowserRouter as Router,Route} from "react-router-dom" 

var About =()=>{ 
    return <div>About us{}</div> 
} 

class App extends Component{ 
render(){ 
return (
    <Router> 
<div> 
     <Route path ="/" component={About}/> 
     <Route path ='/about'component={About}/> 
</div> 
    </Router> 
); 
} 
} 
export default App; 

main.js入口點(的WebPack)

import React from "react" 
import ReactDOM from "react-dom" 
import App from "./components/App.jsx" 

ReactDOM.render(

     <App />, 
     document.getElementById('table') 
); 

我'使用 「反應路由器-DOM」: 「^ 4.0.0-beta.7」

回答

0

Link添加到您的comp onent,改變路線,把它寫這樣的:

import {BrowserRouter as Router,Route, Link} from "react-router-dom" 

class App extends Component{ 
    render(){ 
    return (
     <Router> 
     <div> 
      <Link to='/about'>About </Link> 
      <Route path ="/" component={About}/> 
      <Route path ='/about'component={About}/> 
     </div> 
     </Router> 
    ); 
    } 
} 
export default App; 
+0

非常有用)th'x –