New Angular2 Router support in Ionic


#1

A simple question, when will the new angular2 router be enalbed and supported in new amazing ionic2 framework.

Are there a roadmap for this? Could it be released with beta 11?


#2

I asked Would "@angular/router": "3.0.0-beta.1" work with beta.10 yesterday. And here is what I tried

package.json

"@angular/router": "3.0.0-beta.2",

app/routes.ts

import { provideRouter, RouterConfig } from '@angular/router';
import { DetailPage } from './pages/detail/detail';

export const routes: RouterConfig = [
  { path: 'detail', component: DetailPage },
];

export const APP_ROUTER_PROVIDERS = [
  provideRouter(routes)
];

index.html

<base href="/">

app.ts

import {APP_ROUTER_PROVIDERS} from './routes';

ionicBootstrap(MyApp, [APP_ROUTER_PROVIDERS], {});

In another page

import {ROUTER_DIRECTIVES} from '@angular/router';

template: `<a [routerLink]="['/detail']"`>Go detail</a>
directives: [ROUTER_DIRECTIVES]

Basically I followed https://angular.io/docs/ts/latest/guide/router.html

But it doesn’t work, there’s an error in the console when I issue ionic serve, I’m still trying to figure it out why.


How can I use latest @angular/router 3.0.0-beta.2 in ionic 2?
Simple question on routing, I am unable to find a component in app.component.ts which is from another module
Would "@angular/router": "3.0.0-beta.1" work with beta.10
#3

The console error I’ve been seeing is

Error: Uncaught (in promise): Error: Cannot match any routes: ''

#4

The ionic team disabled supporting the router when it was deprecated and created a new alpha router.
The team told me they will support the router new it is stable, but I my question was, when this will happen. I know they now are working on it but the last two beta releases the router was still not supported.


#5

@itlr have you tried setting up a rule for blank ‘’.
{
path: ‘’,
// /redirectTo: ‘/login’,
component: LoginComponent
}

Either you can redirect it to another rule or can load a default component , in my case loginComponent.


#6

Were you able to get this working with Beta 11? If so, can you post a follow up of how? I’m getting the same errors that you are.


#7

@morrisonbrett Still same situation, angular2 router will never work with ionic, wait for new ionic2 router which will released hopefully soon. (beta.12 or rc.1)


#8

Based on this commit history, I don’t see it being worked on: https://github.com/driftyco/ionic/compare/v2.0.0-beta.11...master


#9

I haven’t tried it on beta.11 yet. I was hoping ionic 2 team could come up with an example.


#10

In general the new router works. Things to note:

  • use “@angular/router”: “3.0.0-beta.2”
  • have a fallback route {
    path: ‘’,
    redirectTo: ‘/form/main’,
    pathMatch: ‘full’
    },
  • “ionic serve” does not support HTML5 urls (aka no-hash-bang) so you can force angular to use hashes ionicBootstrap(MyApp, [ APP_ROUTER_PROVIDERS, { provide: LocationStrategy, useClass: HashLocationStrategy }, …

BUT
Of course the ionic navigation does not support this (at least currently) so NavController becomes fairly useless. You either use routerLink/Router.navigate("[/somewhere]") or navigate with ionic without support for angular routes. Maybe one day.


#11

No new ionic url router in rc.0 :confused:


#12

This is a deal-breaker for most web apps. @mhartington does the absence of routing support in RC0 imply there’s no plan for support in 2.0.0?


#13

Agree. This is a huge issue for a web project I’ve been working on. I’ve been telling my team that routing is coming. We’ve all been waiting and are beyond disappointed to see it’s still not implemented.


#14

Hey guys! Just need to chime in here quickly.

The router implementation is in the codebase, it was just not documented/user ready for this release.

We understand the frustration, and appreciate yall hanging in there.
As for it’s status, it’s code complete.
We have a few internal folks testing it out at the moment to make sure everything works as expected, and it will be in the next RC.

So long story short…

Router/Deep Linker is done. We’re doing testing before it gets released released. It will be documented in the next RC.

:beers:


Examples for ionic with angular 2 router
#15

We all are programmers and we understand the problems and the time problems for release a new router like this, we know also it is in beta so nothing is for sure.

The problem is some of us, as me, pushed a lot to introduce ionic2 in our company but we also need a url router to create a webapp. And some people as me has to take responsibility and must explain now to management why we are still not able to finish the app, as you know time is money and why we will missing christmas business for our product.

We know it is all in beta, but please don’t say in june it takes a few week (integrating angular2 router) and then after 2 months you say it takes again a few weeks (creating new router) and now after nearly other two months it is still not here.

You all do a incredible good work and we all love ionic2 and your team, but please share more of your road maps and if something will not happen as expected and communicated let us it know as soon as possible.

I hope my personal opinion is understood not wrong! :yum:

Thx you sincerely


Runtime Error Uncaught (in promise): invalid views to insert
#16

Thanks, Mike! I took a look at the code and it looks like a config object with a links array gets passed to IonicModule::forRoot, but I’m not clear on how to define a route/link. I see a link can have a name, component, and segment. Is the segment the same format as a path string I’d use in a route object in the angular2 router? I’m sure you have some docs on the way, but any guidance you could provide to help us get started with this would be great.


#17

I’ll be adding docs to this in the coming days, and “should” land in the nightly docs sooon.


#18

Thank you for your hard and superb work.
Is there any documentation on how to use this yet? It will be very useful.


#19

@mhartington,

I noticed some documentation on http://ionicframework.com/docs/v2/api/navigation/DeepLinker/. I tried to implement it, but it’s not apparent how to get it to work. Is this the correct documentation? Any examples available?

Thanks!


#20

Hi @mhartington,

What about lazy-loading? Is DeepLinker related to lazy-loading? The rc0 upgrading guide refer the angular ngModule page which also mentioned lazy loading. Do it means we can use angular router + lazy loading in ionic rc0? Can you guys provide a simple lazy loadnigrouter example/plunker ? We have a hard time to use lazy loading in rc0. Lazy loading is essential for our app, our app has 50+ pages.

Thanks a lot.