Skip to content
Advertisement

ReactJs Link Not Able To Navigate To Respective Component

I am using “Link” in my component to navigate and pass respective data through props to other component. I have below primary component as AllSuppliers which is using Link to navigate to EditSupplier component.

JavaScript

When Clicked On Edit Link , component not getting navigated. Just browser url is getting changed.

enter image description here

As seen in the image , only browser url is getting changed but cannot see contents from EditSuppliers. Contents in the image are from AllSuppliers component. What could be the cause?

EDIT 1 :-

I tried to wrap my App with Router in App.js as –

JavaScript

I observed the same behavior.

Also I tried wrap Router inside AllSuppliers – before and after <table> </table>

I observed same behavior in this case too.

Edit 2 :-

JavaScript

Advertisement

Answer

Issue

You are rendering each link into its own Router context when mapping each supplier.

JavaScript

The problem here is that each Link will use the routing context of the closest Router above it in the ReactTree, so you’ll see the URL change in the address bar but the Router handling all your application’s routes doesn’t get updated.

You also appear to be missing any sort of actual routing in your app.

JavaScript

Solution

Remove the extraneous Router components. Just ensure that there is at least one Router wrapping your app to provide the routing context.

JavaScript

Define the routes for your app to render.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement