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

170
Visualizações
react.js & django, useParams unable to navigate to the page

I am current building a react app with django, I am trying to navigate from the HomePage to the DataPage with corrsponding id. However, it return Page not found error. I am using react-router-dom v6.

Using the URLconf defined in robot.urls, Django tried these URL patterns, in this order:

admin/
api/
api-auth/
homepage
homepage/data
The current path, homepage/data/54, didn’t match any of these.

Here is my App.js

export default class App extends Component {
  constructor(props) {
    super(props);
  }

  renderHomePage() {
    return (
        <HomePage />
    );
  }

  render() {
    return (
      <BrowserRouter>
        <Routes>
          <Route exact path='homepage/' element={this.renderHomePage()} />
          <Route path='homepage/data/:id' element={<DataPage />} />
        </Routes>
      </BrowserRouter>
    )
  }
}

const appDiv = document.getElementById("app");
render(<App />, appDiv);

And I want to navigate to the DataPage below:

const EmtpyGrid = theme => ({
    Grid: { ... }
});


function DataPage(props) {
    const { classes } = props;
    const { id } = useParams();

    return (
        <div>
          ... some material ui components ...
        <div/>
    )
};

DataPage.propTypes = {
    classes: PropTypes.object.isRequired,
  };


export default withStyles(EmtpyGrid)(DataPage);

I was thinking whether I need configure my url.py in frontend as well, and I need to define a designated value for {id} returned from the materialui component first. Perhaps I need a button or <Link><Link/> for the navigation instead of just simply typing in the url? Still, no luck after many attempts. I am so confused right now.

If you know what is wrong with my code, please feel free to leave a comment. Thanks

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

0

After many tries and checking documents, I don't really need to configure my urls.py. I only things that I am missing is to put a parameter in my naviagate() from onRowClick={((rowData, event) => {navigate('data/');})} to onRowClick={((rowData, event) => {let id = event.sample_ID; navigate('data/' + id)})}; I was thinking the problem too complicated.

Thanks you guys for sharing!

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