Ionic-framework: Ionic2: Can't find any information on how to implement URL routing

Created on 17 Feb 2016  路  23Comments  路  Source: ionic-team/ionic-framework

While entering the app in a webpage I need to be able to go to the URL /SomeId to make it easier for users to find what they are looking for but I can't find any information on how to implement URL routing.

When using the native apps the new routing is really cool ;)

Most helpful comment

Will routing be added to the ionic 2 roadmap or to one of the github milestones anytime soon so we can get a hint on when to expect this?

All 23 comments

Angular2's router is currently going through some changes, and for that reason I've held off a little bit on showing how to use routing with Ionic. I've slated it for beta.5 to reevaluate how Ionic ties in with ng2 router. Until then, you can take a look at this example on how it currently works: https://github.com/driftyco/ionic/blob/2.0/ionic/components/nav/test/routing/index.ts#L47

Thanks for the quick response!
I think I've tried that approach without success but I'll give it another go :)

Will the state routing still work when using this? I got it to work once or twice but it is not stable :S
http://localhost:8100/#/test worked once then it stopped working :P

My mistake, forgot to remove

this.rootPage = HelloIonicPage;

Hi @adamdbradley. Can we have a bit more information about ionic 2 routing now ? It's seems not use the same behaviour / interfaces that Angluar 2 provides.. I can't trigger some of these provided here : https://angular.io/docs/ts/latest/api/router/OnActivate-interface.html

And also, I can't get rid of this "HashLocationStrategy" that ionic2 seems to override or something else. Is there an option to custom it ? (With PathLocationStrategy I mean)

Thanks !

@adamdbradley @brandyscarney the URL you guys shared is not accessible
https://github.com/driftyco/ionic/blob/2.0/ionic/components/nav/test/routing/index.ts#L47

Could you guys please share a sample working sample of how routing works in ionic2 even if it is not final? At least we can try and proceed. Thanks

Note: Angular is refactoring their router again and it is not working with the latest version of Ionic (beta 7). From our changelog:

The Angular router is currently under heavy development and refactoring. As a result of this, Angular鈥檚 router is currently disabled within Ionic. If your app requires use of the router we recommend waiting until a future release of Ionic when Angular has completed work on the new router. However, this does not affect Ionic鈥檚 navigation system and it continues to work with the same API from previous versions.

Will routing be added to the ionic 2 roadmap or to one of the github milestones anytime soon so we can get a hint on when to expect this?

@brandyscarney Can we get an update on when this is going to be addressed? Also, is there a preferred way to prevent auto-reload from redirecting to your rootPage? Getting bumped back there every save is sort of a bummer.

Isn't it something like DeepLinker which is described in API docs ?

I don't think so:

Unlike traditional web apps, URLs don't dictate navigation in Ionic apps.

@snowcxt Can you link the source of that quote?

@ronakkaria https://ionicframework.com/docs/v2/api/navigation/DeepLinker/

They also say this here:

When it comes to URLs, Ionic 2 works a bit differently than Ionic 1. Instead of using URLs to navigate, we use them to make sure we can always come back to a page (on app launch, for example). This means we aren鈥檛 limited to using href to navigate around. However, we still have the option to use a URL to navigate to a page when necessary.

You can use the 'locationStrategy' Config option now. I'm not sure when it went in, but I'm using the Angular router and wanted to get rid of the hash, and that option did the trick. I didn't see this option in the docs and only found it digging through the source code.

You can use it like this:

IonicModule.forRoot(AppComponent, { locationStrategy: 'path' })

@todrules - Any chance you could provide a full example of using the path location strategy?

Here is an example of using the path location strategy - http://plnkr.co/edit/syUH0d6SJd2gAjqaPLwr?p=preview

Just a quick note, to get working page reloading while 'ionic serve' use IonicModule.forRoot(AppComponent, { locationStrategy: 'hash' })

This will generate /#/-Url's and reloading a deeplinked page will work. I did not find a way to enable mod_rewrite in ionic-cli for now.

Is Deeplinker has ability of nesting and lazy loading the modules ? Im actually converting the angular2 web app to hybrid app.

How the deep linker read question mark with parameters url (eg: http://localhost:8100/#/resetpassword?key=xxxxxxxx&[email protected])
when my client click email link, the ionic 2 app opens and redirect to resetpassword page, but finally i will go the the home page, all the key and email parameters are gone.

Please help me, thx guys

Hi @DamengRandom , did you find a solution? I'm facing the same problem.
Thanks!

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brandyscarney picture brandyscarney  路  3Comments

gio82 picture gio82  路  3Comments

Nick-The-Uncharted picture Nick-The-Uncharted  路  3Comments

daveshirman picture daveshirman  路  3Comments

vswarte picture vswarte  路  3Comments