简体   繁体   中英

How to save previous component DOM in react

Root.js

const Root = () => (
    <HashRouter>
        <div>
            <Route exact path="/" component={Main}/>
            <Route path="/main/:page" component={Main}/>
            <Route path="/detail/:name" component={Detail}/>
        </div>
    </HashRouter>
);
export default Root;

Main in ItemList.js

render() {
    let count = 0;
    return (
        <div>
            {this.state.data.map(function (data, i) {
                count++;
                return <Item data={data} key={count} order={count}/>;
            })}
        </div>
    );
}

Item is scroll bottom to(more view) append data( use ajax )

Item Click to Link to={item idx} and go to detail page

and back to page.. reset dom!

how to save dom?!?

Save the data somewhere, so when you back to index, load the data in the page. Redux map help you to do all the things. And remember react is a data-driven framework. You get the data, you have the view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM