Using React in a multi-page app

后端 未结 6 761
滥情空心
滥情空心 2021-01-29 17:21

I have been playing around with React and so far I really like it. I am building an app with NodeJS and would like to use React for some of the interactive components across the

6条回答
  •  有刺的猬
    2021-01-29 18:08

    I'm building an application from the ground up and am learning as I go, but I think what you are looking for is React-Router. React-Router maps your components to specific URLs. For example:

    render((
        
            
                
                   
                   
                
            
            
        
    ), document.body)
    

    In the search case, 'term' is accessible as a property in the AnimalSearchBox:

    componentDidMount() {
        // from the path `/api/search/:term`
        const term = this.props.params.term
    }
    

    Try it out. This tutorial is the one that put me over the top in terms of my understanding of this and other related topics.


    Original answer follows:

    I found my way here looking for the same answer. See if this post inspires you. If your application is anything like mine, it will have areas that change very little and varies only in the main body. You could create a widget whose responsibility it is to render a different widget based upon the state of the application. Using a flux architecture, you could dispatch a navigation action that changes the state your body widget switches upon, effectively updating the body of the page only.

    That's the approach I'm attempting now.

提交回复
热议问题