Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何使用redux数据将react应用程序发送到一起?_Reactjs_Redux_React Router - Fatal编程技术网

Reactjs 如何使用redux数据将react应用程序发送到一起?

Reactjs 如何使用redux数据将react应用程序发送到一起?,reactjs,redux,react-router,Reactjs,Redux,React Router,来自一个有角度的背景,我将使用ui路由器来实现这一点,目前正在学习如何使用react.js和redux。这是关于react和redux我最不需要了解的事情。通过数据连接两个组件的方法是什么?基本上我想要的是有人点击{article.title}作为链接。它将转到文章组件,在那里它将显示带有该数组的所有信息,如作者、文章等重要信息,如新闻网站上的信息。如何对列表和文章部分进行编码,使它们相互连接,并通过路由将其连接到列表部分。希望这个问题足够清楚明白。另外,文章部分是从my backend fin

来自一个有角度的背景,我将使用ui路由器来实现这一点,目前正在学习如何使用react.js和redux。这是关于react和redux我最不需要了解的事情。通过数据连接两个组件的方法是什么?基本上我想要的是有人点击{article.title}作为链接。它将转到文章组件,在那里它将显示带有该数组的所有信息,如作者、文章等重要信息,如新闻网站上的信息。如何对列表和文章部分进行编码,使它们相互连接,并通过路由将其连接到列表部分。希望这个问题足够清楚明白。另外,文章部分是从my backend fine获取数据,以便当前可以正常工作

数据集

[{"_id":"58c71df9f7e4e47f1fe17eeb","article":"words words","author":"Jason","date":"1/2/2014","title":"my article","__v":0}, aka bunch more data]
列表组件

  import React from "react"
import { connect } from "react-redux"
import { Link } from 'react-router';

import { fetchArticle } from '../../actions/fashionActions';

@connect((store) => {
    return {

        articles: store.articles.articles,
    };
})
export default class FashionArticle extends React.Component {


    fetchArticle() {
        this.props.dispatch(fetchArticle())
    }

    render() {
        const { articles } = this.props;

        if (!articles.length) {
            return <button onClick={this.fetchArticle.bind(this)}>load Articles</button>
        }

        const mappedArticles = articles.map(article =>
<div>
    <Link to={`fashionArticle/${articles.id}`}>{articles.title}</Link>
</div>
        )

        return <div>
            <h1>List of Fashion Article</h1>
            <ul>{mappedArticles}</ul>
        </div>
    }
}
import React from "react"
import { connect } from "react-redux"
import { Link } from 'react-router';

import { fetchArticle } from '../../actions/fashionActions';

export default class FashionArticle extends React.Component {


}
路线

<Router history={hashHistory}>
    <Route path="/" component={Layout}>
      <IndexRoute component={HomePage}></IndexRoute>
        <Route path="about" name="about" components={AboutPage}/>
        <Route path="fashionlist" name="fashionlist" components={FashionList} /> // the list of data
        <Route path="fashionarticle/:id" name="fashionarticle" components={FashionArticle}/> // what the click on the will go to
    </Route>
  </Router>

//数据列表
//单击将转到什么位置

有两种时尚产品。FashionList在哪里?如果我理解正确,您希望在用户单击链接时显示fashion文章,请使用
链接
反应路由器
作为
访问fashion文章
。现在,存储区中已经有了文章数据,因此您可以轻松地从存储区获取和显示UI上的数据。它与来自标题、作者、摘要等的所有信息一起转到fashionArticle。无论如何,我对列表组件进行了更改,添加了{article.title}它根据我想要的数据提供了我的第一篇文章,但它不会转到fashionArticle页面,url返回为{articles.id}在Link中,当使用模板字符串文字时,您需要使用backticks,所以将'fashionArticle/${articles.id}'更改为
`fashionArticle/${articles.id}`
。所以,最后您的链接应该是,
{articles.title}
doing{articles.title}导致链接完全不显示在列表组件上…有两个FashionArticles。FashionList在哪里?如果我理解正确,您希望在用户单击链接时显示fashion文章,请使用
链接
反应路由器
作为
访问fashion文章
。现在,存储区中已经有了文章数据,因此您可以轻松地从存储区获取和显示UI上的数据。它与来自标题、作者、摘要等的所有信息一起转到fashionArticle。无论如何,我对列表组件进行了更改,添加了{article.title}它根据我想要的数据提供了我的第一篇文章,但它不会转到fashionArticle页面,url返回为{articles.id}在Link中,当使用模板字符串文字时,您需要使用backticks,所以将'fashionArticle/${articles.id}'更改为
`fashionArticle/${articles.id}`
。所以,最后您的链接应该是,
{articles.title}
doing{articles.title}导致链接完全不显示在列表组件上。。。