Disable Deep Linking?


#1

I’m probably just not seeing the relevant documentation somewhere obvious, despite having looked in the docs and searched this forum, but can anyone tell me how to disable deep linking in an Ionic3 app with lazy loading. At this point in time I do not want any deep links.

Any help appreciated…


ionicPage Setting URL Path
#2

I don’t think that’s possible. The lazy loading is implemented using the deeplinker, so if you really want to get rid of deep links, you’ll need to disable lazy loading by deleting all the [page].module.ts files, removing the @IonicPage decorator from all classes, and declaring things in the app module as before.


#3

Thanks for that. I was afraid that would be the case. Time to roll my project back to an earlier commit :frowning:


#4

Just our of curiosity: May I ask why?


#5

No Problem. It’s simply due to authentication. I don’t want anyone not authenticated accessing areas of the app that should require authentication.

At present the app is ‘just’ intended for installation on IOS / Android as a cordova project, but I can see a place for it as a PWA in the future, too. In a browser though you can easily experiment with URLs to see what you can see, and as it stands right now you could probably get at things you shouldn’t really get at without going through the logon. I have to put a load more guards on pages before I’ll go with deep links. It’s just a product of how the app is structured right now and not a task I really need to tackle this moment.


#6

Obviously it’s your app and your priorities, but I cannot think of a more important task, and the longer you put it off, the more arduous it’s going to be, both to implement and to test. In fact, if this is a typical communicate-with-backend type of app, more importantly than ensuring that this-or-that page does or doesn’t show on the Ionic side is ensuring that the backend enforces its own security, because it’s a huge mistake to assume that that sort of security can be done client-side at all.


#7

Ah yes, normally I’d agree and that’s how I’d structure things, but it’s priority use is to work offline. Authentication is obviously required for the online part (syncing data when possible) and to initially ‘unlock’ the app, but it’s for use in situations where day to day (or even week to week) connectivity is an unexpected and unusual bonus, not an expectation, so any page by page authentication cannot be with any backend system.


#8

And what about implementing some custom guards as discussed over here Ionic 2 Route Guards? ? I suppose this could be a welcome addition to the Deeplinker someday.


#9

Not the cleanest solution, but if you want to disable deeplinks, you can do the following:
Add location.hash = ''; to your index.html (before loading your app bundle).

This way, the app will still generate the location URL when navigating through the app, but when loading the page with a specific URL path will just bring you back to the root.


#10

Thanks. This does pretty much what I wanted.


#11

Perfect thank you for this - that fixed my problems which were a total pain, I added this to my index.html:

  <script>
    location.hash = '';  
  </script>

#12

If there are a link “http://localhost:8100/#/member-area” and user know the link.
They still can direct access this page after page loaded.