Angular 路由与 Ionic 路由
Angular routing vs Ionic routing
我是 ionic2 的新手。与纯 angular 路由相比,它的路由有些奇怪。在 Angular:
const appRoutes: Routes = [
{ path: 'crisis-center', component: CrisisListComponent },
{ path: 'hero/:id', component: HeroDetailComponent },
{
path: 'heroes',
component: HeroListComponent,
data: { title: 'Heroes List' }
},
{ path: '',
redirectTo: '/heroes',
pathMatch: 'full'
},
{ path: '**', component: PageNotFoundComponent }
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes)
// other imports here
],
我们传递类型为 Routes
的常量。
在 Ionic(sidemenu starter)中,他们将组件传递给 forRoot
函数。
import { MyApp } from './app.component';
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
],
有什么想法吗?
编辑:
Ionic 4 还在 background.Pushing 中使用标准 angular 路由,弹出不再是离子方式,here 是一本关于使用 angular 路由器的好书离子。
原答案:
Ionic 不支持 URL 路线,而是实现了自定义导航解决方案 - NavController(由 suraj 链接)。 NavController 维护一个页面堆栈 - 向前移动将页面推入堆栈 this.nav.push(Page1);
并向后移动将其弹出 this.navCtrl.pop();
。
通过这种方式,您在浏览器中的 url 始终相同,并且应用程序始终在主页上打开 - 这类似于移动应用程序的行为。要启用对特定资源的直接访问(如打开 url myapp/items/1),您必须使用 deep linking plugin.
在 ionic 中,我们从另一个视图推送一个视图屏幕
但在 angular 中是预定义的路由映射,如果您转到此路由,即 app/login 您将被重定向到与 loginComponent
绑定的登录路由
我是 ionic2 的新手。与纯 angular 路由相比,它的路由有些奇怪。在 Angular:
const appRoutes: Routes = [
{ path: 'crisis-center', component: CrisisListComponent },
{ path: 'hero/:id', component: HeroDetailComponent },
{
path: 'heroes',
component: HeroListComponent,
data: { title: 'Heroes List' }
},
{ path: '',
redirectTo: '/heroes',
pathMatch: 'full'
},
{ path: '**', component: PageNotFoundComponent }
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes)
// other imports here
],
我们传递类型为 Routes
的常量。
在 Ionic(sidemenu starter)中,他们将组件传递给 forRoot
函数。
import { MyApp } from './app.component';
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
],
有什么想法吗?
编辑:
Ionic 4 还在 background.Pushing 中使用标准 angular 路由,弹出不再是离子方式,here 是一本关于使用 angular 路由器的好书离子。
原答案:
Ionic 不支持 URL 路线,而是实现了自定义导航解决方案 - NavController(由 suraj 链接)。 NavController 维护一个页面堆栈 - 向前移动将页面推入堆栈 this.nav.push(Page1);
并向后移动将其弹出 this.navCtrl.pop();
。
通过这种方式,您在浏览器中的 url 始终相同,并且应用程序始终在主页上打开 - 这类似于移动应用程序的行为。要启用对特定资源的直接访问(如打开 url myapp/items/1),您必须使用 deep linking plugin.
在 ionic 中,我们从另一个视图推送一个视图屏幕
但在 angular 中是预定义的路由映射,如果您转到此路由,即 app/login 您将被重定向到与 loginComponent
绑定的登录路由