React Router Params
Bu konudaki amacımız. Axios kütüphanesini anlattığımız konuyu pekiştirmek. https://jsonplaceholder.typicode.com/posts adresinden postları çekip. Ardından Post id ye göre postun tamamını göstermek. Bu işleyişi yaparken Routerden parametreleri almayı öğreneceğiz. Reac ve router kurulumlarınızı yaptığınızı varsayarak devam ediyorum. Route kodum : < Route path = '/Post/:Post_id' component = { Post } /> Burada :/Post_id kısmı imlece ne yazarsak Post_id ye atar. Post sayfamın ile tasarımı : http://localhost:3000/post/merhabarouter Şimdi params ımızı almanın yollunu bulalım. React da route bilgileri props ta tutulur. Bir componentDidMount life döngüsü oluşturup props ları log ile gösterip hangisini alacağımı bulacağım. Görüldüğü üzere bir obje döndü. Objenin içinde macth->params->path yolunda params : { Post_id : "merhabarouter" } let id = this .props.match.params.Post_id; Post_id nin yazımı onemlli aynı case sensetived...
Yorumlar
Yorum Gönder