React-Routing当我输入网址时,它们无法正常工作,但当我从root用户开始时,我可以访问它们

时间:2016-10-05 17:19:05

标签: react-router url-mapping

反应框架的新手,并尝试收集有关react-router的智慧。 在使用哈希历史记录(不推荐使用)的教程之后,我现在使用浏览器历史记录

代码:

import React from 'react';
import ReactDOM from 'react-dom';
import {Router, Route, IndexRoute, browserHistory} from 'react-router';

import Bootstrap from './vendor/bootstrap-without-jquery.min';

import Archives from './pages/Archives';
import Featured from './pages/Featured';
import Layout from './pages/Layout';
import Settings from './pages/Settings';

const app = document.getElementById('app');
ReactDOM.render(
<Router history={browserHistory}>
  <Route path="/" component={Layout}>
    <IndexRoute path="/featured" component={Featured} />
    <Route path="archives/:article" name="archives" component={Archives}></Route>
    <Route path="settings" component={Settings}></Route>
</Route>
</Router>,
app);

这是我的布局:

import React from 'react';
import { Link, Router, browserHistory } from 'react-router';

export default class Layout extends React.Component{
navigate(){
    browserHistory.push("/");
}

render(){
    return(
        <div>
            <h1>KillerNews.net</h1>
            {this.props.children}
            <Link to="archives" class="btn btn-info">archives</Link>
            <Link to="settings" class="btn btn-info">settings</Link>
            <button onClick={this.navigate.bind(this)}>featured</button>
        </div>
    );
  }
}

我无法输入网址,我只能在从root开始时访问它们。我没有在服务器端设置任何路径只运行webpack,babel并做出反应。

0 个答案:

没有答案