Reputation: 107
I'm working on angular2. I had to work on the forgot password section for a login page. Where in which when I click on the forgot password link, a url would be sent to my mail https://webview.sample.nationcrossapp//deeplink?tokenNo=1234.
How do I redirect this url to a particular page in my application, also how could I fetch the token 1234 from the url.
Any help would be appreciated. Thanks in advance
Upvotes: 0
Views: 1043
Reputation:
When you create a SPA (Single Page Application) with Angular, you have the opportunity to create several components, that you can access with routing.
Routing is something you set up so that, when a user clicks on a link/button/menu, the application shows the corresponding component.
You can face 2 cases :
1 - The HashLocationStrategy
When you use this, your URL looks like this : http://www.myapp.com/#/home
What happens is that Angular adds a # in your URL. The left part of the # represents the domain name, that you registered for your website.
What is on the right of it, represents the component Angular is showing you. Basically, you tie the right part of the URL to components. Here, for instance, the shown component will be Home. if it ended with with forgotPassword
, then you could display the ForgotPassword component.
With this solution, you don't have to setup your server to do anything other that showing the SPA. This is my recommended case, I always use this one.
2 - The server redirect
When you use this case, your URL looks like this : http://www.myapp.com/home
In this case, you are going on your domain, and request a subdomain (I think, I'm not familiar with that !) which is home. This means that you're actually not requesting a component of the SPA, but a whole another website !
Depending on how you set up your server, http://www.myapp.com/home can be totally different from http://www.myapp.com/.
In this case, this means you have to redirect the user on the page you want. This means that if he goes to http://www.myapp.com/home, you should redirect him to your Home component.
I can't give you more information on how to redirect, because as I told you, I only used the other case. But I'm sure there's plenty of help on the internet !
Now about your other question, abour parameters. I gave you a link to the optional parameters and how they are handled in Angular. In case you didn't read it : Angular uses the Matrix URL notation for handling optional parameters (optional parameters = parameters that are located at the end of the URL, pretty much like you did it).
This means that if you don't use Angular's way of dealing with URl parameters, you will have to implement your own way of dealing with these.
Otherwise, if you use it, then you can follow the tutorial to see how easy it is to handle those parameters !
I hope this whole chunk of text cleared it up for you, and if not, feel free to ask !
Upvotes: 1