Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use <router-link> vs <a>

Should I always be using <router-link> over <a> even if I am linking to something like a social media page outside the app?

like image 782
Allen Trinh Avatar asked Oct 06 '18 05:10

Allen Trinh


People also ask

Should I use href or routerLink?

routerLink is the attribute provided by angular to navigate to different components without reloading the page. Major difference between both is that href kills the state of the current page where routerLink doesnt lose the state of the page.

Why we use routerLink?

RouterLink is a built-in Angular Directive that lets you link to specific routes in your app. In the SPA(single-page application), you change what the user sees by showing or hiding portions of the display that correspond to particular components, rather than going out to the server to get a new page.

What is the difference between link and route?

So in a nutshell, the Link component is responsible for the transition from state to state (page to page), while the Route component is responsible to act as a switch to display certain components based on route state.

Why We Use link in react?

The Link component renders a component that can navigate to a screen on press. This renders an <a> tag when using on the Web and It uses a Text component on other platforms.


1 Answers

<router-link> is intended for in-app links (e.g., to a page within your app). Use <a> for external links.

like image 183
tony19 Avatar answered Oct 10 '22 17:10

tony19