1

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.

1
  • 1
    Can you plz, elaborate your question? Commented Jan 28, 2019 at 2:42

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.