Reputation: 473
I would like to ask if there is any method to check if component or page is accessed by click on router link or typing direct URL in browser?
Thanks for your help.
EDIT: Sorry for not a very precise question. What I mean is to check the way of getting to component, for example:
1.Navigating on page, ex: /posts/ -> click RouterLink -> /posts/someID
2.Typing /posts/someID in browser's address bar
And I'm looking for method to check which way is used.
Upvotes: 1
Views: 1354
Reputation: 21
I guess you already solved your problem, but for everyone else who might visit this page:
Just set a query param on the link button, e.g:
<a [routerLink]="['/posts', postId]" [queryParams]="{navigatingThroughPage: true}">Go to Post</a>
If query param is not present in the component, then it means you accessed the page from outside. If you have multiple links leading to the page, then of course you have to set the query param on every link.
Upvotes: 2