How to make Android deeplinks work?

I want the app to open on a certain screen after clicking on the link if app is installed or there was a transition to the app store if not.

I thought that only the line
window.location.replace("intent://#Intent;scheme=name of app;package=com.domain.app;end");
in JavaScript would be enough. But after clicking on the link with such a script, in any case, a page opens in the store. Even if the app is installed already.