Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
React api router can't show data in detail

Im learning React with routing and api calls at the moment. I've got an api were I need to find all the urls and post them on a page that was successful. But now I need to make a detail page where I can show more information about the url. Page 1 is like : gather all the urls and show them in a list. And page 2 is if you have clicked on a url in the list on page 1 you will be navigated to page 2 where a detail dialog is showed. I have the page 1 completely and I can navigate to page 2 but I can't show any data from the api in page 2 information/detailpage.I don't know how to work with the key and get the info. I Tried several things but none of them works. Im using link.Link as key and I need description property , url , api name.

This is my page 1:

import React from "react";
import {Link, NavLink} from 'react-router-dom';
import { Detail } from './Detail';

export default class FetchLinks extends React.Component {
    state = {
        loading: true,
        links: [],
    };
    async componentDidMount() {
        const url = "https://api.publicapis.org/entries?category=development";
        const response = await fetch(url);
        const data = await response.json();
        this.setState({links: data.entries, loading: false});
    }
    render() {
        if (this.state.loading) {
            return <div>loading...</div>
        }
        if (!this.state.links.length) {
            return <div>geen links gevonden</div>
        }
        return (
            <div>
                {this.state.links.map(link => (
                    <div key={link.Link}>
                        <ul><li>
                            <p>
                                <NavLink to={`/Detail/${link.Link}`}>
                                    {link.Link}
                                </NavLink>
                            </p>
                        </li></ul>
                    </div>))}
            </div>
        );
    }
}

this is page 2:

import React from 'react';
import Content from './Content';

const Detail = () =>{
return(
    <div>
        <h1>Detail Page</h1>
        <p>{this.state.links.Link}</p>
    </div>
)


}
export default Detail();

This is how it should be

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

So if I understood correctly, you have all your data in page 1 and need to pass the data to page 2. For this you have to write your NavLink like this:

 <NavLink to={{
    pathname: `/Detail/${link.Link}`,
    state: link.Link
 }}>
    {link.Link}
 </NavLink>

Now you can use UseLocation hook of react-router to access this state that you just passed. So in page 2:

    import React from 'react';
    import { useLocation } from "react-router-dom";
    
    const Detail = () =>{
       const location = useLocation();         

       return (
          <div>
             <h1>Detail Page</h1>
             <p>{location.state.link}</p>
          </div>
       );

    }

    export default Detail();

You can read more about react-router hooks here.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda