我一直在尝试为仍在开发中的ionic2应用程序设置路由。我对路由的概念完全陌生。到目前为止,我所做的一切都是基于NavCtrl.push()或NavCtrl.setRoot()。我想知道在ionic2中是否可以路由。
但是按照官方网站的代码:https://angular.io/docs/ts/latest/guide/router.html。我在运行应用程序时遇到一些错误。这是我为路由创建的app.routing.ts文件。
import { Routes, RouterModule } from '@angular/router';
import { Contest } from '../pages/contest/contest';
export const appRoute: Routes = [
{ path: '', redirectTo: 'Contest', pathMatch: 'full' },
{ path: 'Contest', component: Contest}
]
export const appRouting = [
RouterModule.forRoot(appRoute)
];
我将此语句导入 app.component.ts 并将其注入到构造函数中。
import { Router } from '@angular/router';
constructor(public platform: Platform,protected _router: Router) {
this.initializeApp();
在 app.module.ts 中,我导入了以下语句,并在 @ngModule 中的导入中设置了它们
import { RouterModule, Routes } from '@angular/router';
import {appRouting} from './app.routing';
imports: [appRouting,
IonicModule.forRoot(MyApp)
]
我把<router-outlet></router-outlet>
在我的应用程序中.html文件。当我尝试运行时执行所有这些操作时,我收到以下错误。
运行时错误:WEBPACK_IMPORTED_MODULE_0__angular_core。版本不是构造函数
打字稿错误: 模块"C:/Users/Impromptu_coder/dem/node_modules/@angular/core/index"没有导出成员"NgProbeToken
打字稿错误: 模块"C:/Users/Impromptu_coder/dem/node_modules/@angular/core/index"没有导出的成员"版本"。
我已经浏览了互联网上许多关于ionic2和angular2路由的资源,但其中大多数似乎已被弃用。以下是当前版本
我正在使用:
离子2 : v2.2.1
NPM:3.10.10
科尔多瓦 : 6.5.0
角度2:最终版本 rc5
请告诉我在我的应用程序中设置路由的确切过程是什么。我需要安装任何依赖项吗?
确保根据离子更改日志中指定的内容设置依赖项: https://github.com/driftyco/ionic/blob/master/CHANGELOG.md
您想在 ionic 2 应用程序中使用角度路由有什么原因吗?离子2导航系统非常直观,与角度导航系统完全不同。我建议坚持使用内置的离子导航,除非您可以定义非常真实的需求。除非你只是出于好奇而尝试使用角度导航。在这种情况下,请更新依赖项并再次尝试。