React动态创建路由

时间:2017-10-25 00:59:29

标签: arrays reactjs react-router

首先,首先可以在页面上有2个组件,一个显示简单的静态标记,但是我父项中的第二个组件将是一个div,它显示数组中每个项目的链接,如果单击它在div的底部,那么每个数据都会显示数据吗?

如果可能的话,动态道具就像在元素中执行.map并打印出路线一样简单吗?

还会补充说我在我的Router对象上收到以下内容但是我在全局安装了react-router,尽管它也在我的node_modules文件夹中。

  

'反应路由器'不包含名为' hashHistory'。

的导出
FROM centos:7
    MAINTAINER Brian Ogden

    RUN yum update -y && \
             yum clean all

    #############################################
    # Jenkins Slave setup
    #############################################
    RUN yum install -y \
            git \
            openssh-server \
            java-1.8.0-openjdk \
            sudo \
            make && \
            yum clean all

    # gen dummy keys, centos doesn't autogen them like ubuntu does
    RUN /usr/bin/ssh-keygen -A

    # Set SSH Configuration to allow remote logins without /proc write access
    RUN sed -ri 's/^session\s+required\s+pam_loginuid.so$/session optional pam_loginuid.so/' /etc/pam.d/sshd

    # Create Jenkins User
    RUN useradd jenkins -m -s /bin/bash

    # Add public key for Jenkins login
    RUN mkdir /home/jenkins/.ssh
    COPY /files/id_rsa.pub /home/jenkins/.ssh/authorized_keys

    #setup permissions for the new folders and files
    RUN chown -R jenkins /home/jenkins
    RUN chgrp -R jenkins /home/jenkins
    RUN chmod 600 /home/jenkins/.ssh/authorized_keys
    RUN chmod 700 /home/jenkins/.ssh

    # Add the jenkins user to sudoers
    RUN echo "jenkins  ALL=(ALL)  ALL" >> etc/sudoers
    #############################################

    # Expose SSH port and run SSHD
    EXPOSE 22
    #Technically, the Docker Plugin enforces this call when it starts containers by overriding the entry command. 
    #I place this here because I want this build slave to run locally as it would if it was started in the build farm.
    CMD ["/usr/sbin/sshd","-D"]

    #############################################
    # Docker and Docker Compose Install
    #############################################
    #install required packages
    RUN yum install -y \
        yum-utils \
        device-mapper-persistent-data \
        lvm2 \
        curl && \
        yum clean all

    #add Docker CE stable repository
    RUN yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo

    #Update the yum package index.
    RUN yum makecache fast

    #install Docker CE
    RUN yum install -y docker-ce-17.06.0.ce-1.el7.centos

    #install Docker Compose 1.14.0
    #download Docker Compose binary from github repo
    RUN curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
    #Apply executable permissions to the binary
    RUN chmod +x /usr/local/bin/docker-compose
    #############################################

    ENV NODE_VERSION 6.11.1

    #############################################
    # NodeJs Install
    #############################################
    RUN yum install -y \
            wget

    #Download NodeJs package
    RUN wget https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz

    #extract the binary package into our system's local package hierarchy with the tar command. 
    #The archive is packaged within a versioned directory, which we can get rid of by passing the --strip-components 1 option. 
    #We will specify the target directory of our command with the -C command:
    #This will install all of the components within the /usr/local branch
    RUN tar --strip-components 1 -xzvf node-v* -C /usr/local
    #############################################

#############################################
# npm -setup volume for package cache
# this will speed up builds
#############################################
RUN mkdir /home/jenkins/.npm
RUN chown jenkins /home/jenkins/.npm .
RUN mkdir /root/.npm
RUN chown jenkins /root/.npm .
#for npm cache, this cannot be expressed in docker-compose.yml
#the reason for this is that Jenkins spins up slave containers using
#the docker plugin, this means that there
VOLUME /home/jenkins/.npm
VOLUME /root/.npm
#############################################

2 个答案:

答案 0 :(得分:2)

使用React Router,您可以设置match参数来动态加载路由。

<Route path="/dynamicroute/:id" component={DynamicComponent}/>

将在id的{​​{1}}内提供this.props.match.params个参数。

因此,如果您发现自己位于网址<DynamicComponent/>"/dynamicroute/helloworld"组件中的this.props.match.params.id将返回<DynamicComponent/>

请注意,如果没有提供"helloworld" params,则只会提供错误:match。对于可选的:id参数,后续问号“?”可以添加即。 match

答案 1 :(得分:-1)

向一些更高级的反应开发人员发言,他们说我追求的是npm package Component-Router我还没有回到项目上,但是一旦完成就会发布完整的代码:)