Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
How to stop reloading screen when go back to previous screen with dom-router in react js

I have a web app with multiple pages and routing, in every single page I have table with lots of data, so every time I change page and press back button, the history page is reloads itself.

I want to keep the data of ListingPage as it is when I goBack to ListingPage from DetailPage. But every time it calls getAllRecords function and reloads the table.

I tried changing dom options and components but still not getting a proper solution

My App page structure is something like as below

App.js

import { BrowserRouter, Route, Switch } from 'react-router-dom';
import HomePage from './Pages/HomePage.js'
import ListingPage from './Pages/ListingPage.js'
import DetailPage from './Pages/DetailPage.js'
render() {
    return (
        <BrowserRouter>
            <Switch>
                <Route path="/home" component={HomePage} />
                <Route path="/list" component={ListingPage} />
                <Route path="/detail" component={DetailPage} />
            </Switch>
        </BrowserRouter>
    )
}

HomePage.js

import React, { Component } from 'react';
class HomePage extends Component {
    render() {
        return (
            <div>
                //Showing list of different table and pages
            </div>
        );
    }
}
export default HomePage;

ListingPage.js

import React, { Component } from 'react';
class ListingPage extends Component {
    componentDidMount(){
        this.getAllRecords()
    }
    getAllRecords = () => {}
    goToDetailRecord = () => {
        this.props.history.push('detail')
    }
    render() {
        return (
            <div>
                //Table list data
            </div>
        );
    }
}
export default ListingPage;

DetailPage.js

import React, { Component } from 'react';
class DetailPage extends Component {
    goBack = () => {
        this.props.history.goBack();
    }
    render() {
        return (
            <div>
                //Shows table data detail value
            </div>
        );
    }
}
export default DetailPage;

Is there anything I can implement to resolve the issue. Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can either useMemo or the react 16 and older version of that to store a cache to prevent it doing so on re renders or save the value in state using redux and not call the function if the field isn't empty. Also if component did mount works like useEffect I think by you having it there it will call that function on each re render.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda