React-Router,在`Link`中没有指定prop`to`

时间:2016-03-18 22:49:48

标签: javascript reactjs react-router

我正在尝试实施event.stopPropagation(),但我收到以下错误:

  

propType失败:react-router中未指定必需的道具to。校验   Link的渲染方法。

我不确定我的代码有什么问题。

./应用程序/ app.js

app

./应用程序/布局/ app.js

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

// Layouts
import App from 'layouts/app';

// Components
import Portfolio from 'ui/portfolio';
import Blog      from 'ui/blog';
import TimeLine  from 'ui/timeline';
import About     from 'ui/about'
import Contact   from 'ui/contact'


ReactDOM.render((
    <Router history={browserHistory}>

        <Route component={App}>

            <Route path="/" component={Portfolio} />
            <Route path="/blog" component={Blog} />
            <Route path="/timeline" component={TimeLine} />
            <Route path="/about" component={About} />
            <Route path="/contact" component={Contact} />

        </Route>

    </Router>
), document.getElementById('root'));

您可以在下面看到我正在使用的依赖项。

import React from 'react';
import { Link } from 'react-router';

export default React.createClass({
    render: function() {
      return (
        <div className="app">
            <nav>
                <Link to="/">Portfolio</Link><br />
                <Link to="/blog">Blog</Link><br />
                <Link toc="/timeline">TimeLine</Link><br />
                <Link toc="/about">About</Link><br />
                <Link toc="/contact">Contact</Link>
            </nav>
            <main>
                {this.props.children}
            </main>
        </div>
      )
    }
});

知道发生了什么事吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

<Link toc="/timeline">TimeLine</Link><br />
<Link toc="/about">About</Link><br />
<Link toc="/contact">Contact</Link>

您希望to不是toc

<Link to="/timeline">TimeLine</Link><br />
<Link to="/about">About</Link><br />
<Link to="/contact">Contact</Link>