2016-06-11 74 views
1

我想在我的應用程序中實現React-Router。我已經在index.js中初始化了路由器,它工作正常。但它不會更改瀏覽器中的URL並在控制檯中引發此錯誤。反應路線中的URL不會改變

警告:[react-router]`Router`不再默認history歷史記錄。請改用`hashHistory`單例。

Index.js

import 'core-js/fn/object/assign'; 
import React from 'react'; 
import ReactDOM from 'react-dom'; 
import { Router, Route, browserHistory,IndexRoute } from 'react-router'; 

// Custom Components 
import App from './components/Main'; 
import Dashboard from './components/containers/Dashboard'; 
import Settings from './components/containers/Settings'; 
import Workspace from './components/containers/Workspace'; 
import Main from './components/Main'; 

ReactDOM.render((

    <Router histrory={browserHistory}> 
    <Route path="/" component={Main}> 
     <IndexRoute component={Dashboard}></IndexRoute> 
     <Route path="/workspace" component={Workspace}></Route> 
     <Route path="/dashboard" component={Dashboard}></Route> 
     <Route path="/settings" component={Settings}></Route> 
    </Route> 
    </Router> 


), document.getElementById('app')); 

Main.js

require('normalize.css/normalize.css'); 
require('styles/App.scss'); 

//Import Custom Components 
import React from 'react'; 
import { Router, Route,Link, browserHistory } from 'react-router'; 

import Sidenav from './containers/Sidenav'; 
import Page from './Page'; 


class AppComponent extends React.Component { 
    render() { 
    return (
     <div> 
     <Sidenav /> 
     <div className="page-wrap"> 
      {this.props.children} 
     </div> 
     </div> 
    ); 
    } 
} 

AppComponent.defaultProps = { 
}; 
export default AppComponent; 

路線是工作的罰款和組件是越來越正確呈現。請建議將其與網址綁定。

預先感謝您。 :d

+1

拼寫歷史是錯誤的?這是你的代碼中的拼寫錯誤嗎? –

回答

1

你有<Router histrory={browserHistory}>一個錯字 - 歷史

+0

感謝@dimitriy對於這一點,但仍然沒有修復。我的路由仍在工作,但URL沒有改變。 –

+0

你是否仍然有同樣的警告? –

+0

是的,那已經過去了 –