Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between html tag "/href" and navlink or Link

what is the difference between html tag "/href" and navlink provided by react-router to navigate the page? I can use both in order to navigate page to the different URL, so why there was need of introducing Navlink or Link?

like image 485
deepak katara Avatar asked Oct 28 '25 14:10

deepak katara


2 Answers

The href attribute would trigger a page refresh which would reset the application states. However the link and navlink of react-router doesn't trigger a page refresh. Since React is used to create single page applications most of the time make sure you choose Link or Navlink when working with routing

like image 103
Muljayan Avatar answered Oct 31 '25 07:10

Muljayan


If we were to create links using anchor elements such as href, clicking on them would cause the whole page to reload. React Router provides a <Link> component to prevent that from happening. When clicking a <Link>, the URL will be updated and the rendered content will change without reloading the page. So basically to sum up this navlink/ link provided by react doesnt refresh the page while href refreshes the page

like image 26
Rubin bhandari Avatar answered Oct 31 '25 05:10

Rubin bhandari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!