I am developing an Ionic 3 application. Right now I am using NavController
for routing and switching pages.
Ex : this.navCtrl.push(DetailsPage);
But I need to use Angular routing now.
I found similar question for Ionic 2, but does this work in Ionic 3 as well?
Can someone elaborate this?
to A redirect route, redirects "from" a URL "to" another URL. This property is that "to" URL. When the defined ion-route-redirect rule matches, the router will redirect to the path specified in this property.
The router is a component for handling routing inside vanilla and Stencil JavaScript projects. Note: this component should only be used with vanilla and Stencil JavaScript projects. For Angular projects, use ion-router-outlet and the Angular router. Apps should have a single ion-router component in the codebase.
Angular router traverses the URL tree and matches the URL segments against the paths configured in the router configuration. If a URL segment matches the path of a route, the route's child routes are matched against the remaining URL segments until all URL segments are matched.
Check this link for the detail of NavController link. Which you have to import into your current ts file, followed by =>
There are two ways of navigation we can make use in ionic
1) DeepLink
2) Component navigation stack
DeepLink
deeplink navigation acts like webpage navigation like below example you have to use @ionicpage anotation in order to use deeplink navigation
https://locallhost:8000/#/HomePage/SecondPage
Component Navigation
You have to import your component in the respected ts file in order to navigate
There are three key words push, pop, setRoot.
setRoot
Example:
this.navCtrl.setRoot(HomePage);
(or)
this.navCtrl.setRoot("HomePage"); //DeepLink navigation
Used to make the component as Root page, in other words, it creates an empty navigation stack where homepage is the root.
push
Example:
this.navCtrl.push(SecondPage);
(or)
this.navCtrl.push("SecondPage"); //DeepLink navigation
The above example has push keyword where the navigation stack has one component inside its stack followed by Homepage. I mean, after homepage component, you will be having secondpage component in the navigation stack (HomePage/SecondPage).
pop
Example:
this.navCtrl.pop();
(or)
this.navCtrl.pop(); //DeepLink navigation
Consider you are in secondpage now and wanted to go back to the previous page which is home page. Then just use the above example it will pop one component from the navigation stack and gives you only the homepage component in the navigation stack.
You can use Ionic deep links for that.
Example from the doc:
@IonicPage({
name: 'my-page',
segment: 'some-path'
})
When navigating to this page as the first page in the app, the URL will look something like this:
http://localhost:8101/#/some-path
Good article about it: Link to Pages via URLs with Deep Linking in Ionic
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With