ionic2的页面可以支持嵌套目录结构吗?
Can ionic2's pages support nested directory structure?
我看到很多Ionic 2项目的pages
目录是扁平化的结构,如下图(如果我们使用它的生成命令,生成的目录结构是扁平化的)。
例如
pages/
|- login/
| |-login.html
| |-login.scss
| |_login.ts
|- logout/
| |-logout.html
| |-logout.scss
| |_logout.ts
|- order-list/
| |-order-list.html
| |-order-list.scss
| |_order-list.ts
|- order-detail/
| |-order-detail.html
| |-order-detail.scss
| |_order-detail.ts
但是如果一个项目包含很多页面,我希望pages
目录支持如下子目录:
例如
pages/
|- auth/
| |- login/
| | |-login.html
| | |-login.scss
| | |_login.ts
| |- logout/
| | |-logout.html
| | |-logout.scss
| | |_logout.ts
|- order/
| |- list/
| | |-list.html
| | |-list.scss
| | |_list.ts
| |- detail/
| | |-detail.html
| | |-detail.scss
| | |_detail.ts
Ionic 2 的 pages
支持吗?对其他目录的相同问题,如 providers
和 pipes
.
是的。确实如此。
在 src/app/app.module.ts
中为您的 NgModule 导入页面时,您只需要尊重嵌套
当然可以。事实上,与其根据 它们是什么 (页面、提供程序、管道、指令等)对事物进行分组,我更喜欢根据 对它们进行分组他们所做的就像Angular 2 style guides推荐的那样。
Folders-by-Feature Structure STYLE 04-07
Do create folders named for the feature area they represent.
Why? A developer can locate the code, identify what each file
represents at a glance, the structure is as flat as it can be, and
there is no repetitive nor redundant names.
Why? The LIFT guidelines are all covered.
Why? Helps reduce the app from becoming cluttered through organizing
the content and keeping them aligned with the LIFT guidelines.
Why? When there are a lot of files (e.g. 10+), locating them is easier
with a consistent folder structure and more difficult in a flat
structure.
请记住,您必须更新所有文件和组件中的引用 templateUrl
属性(如果您 不是 使用 RC 版本)。所以
@Component({
templateUrl: 'build/pages/login/login.html',
pipes: [ ... ],
directives: [ ... ]
})
...
会变成:
@Component({
templateUrl: 'build/pages/auth/login/login.html',
pipes: [ ... ],
directives: [ ... ]
})
...
我看到很多Ionic 2项目的pages
目录是扁平化的结构,如下图(如果我们使用它的生成命令,生成的目录结构是扁平化的)。
例如
pages/
|- login/
| |-login.html
| |-login.scss
| |_login.ts
|- logout/
| |-logout.html
| |-logout.scss
| |_logout.ts
|- order-list/
| |-order-list.html
| |-order-list.scss
| |_order-list.ts
|- order-detail/
| |-order-detail.html
| |-order-detail.scss
| |_order-detail.ts
但是如果一个项目包含很多页面,我希望pages
目录支持如下子目录:
例如
pages/
|- auth/
| |- login/
| | |-login.html
| | |-login.scss
| | |_login.ts
| |- logout/
| | |-logout.html
| | |-logout.scss
| | |_logout.ts
|- order/
| |- list/
| | |-list.html
| | |-list.scss
| | |_list.ts
| |- detail/
| | |-detail.html
| | |-detail.scss
| | |_detail.ts
Ionic 2 的 pages
支持吗?对其他目录的相同问题,如 providers
和 pipes
.
是的。确实如此。
在 src/app/app.module.ts
中为您的 NgModule 导入页面时,您只需要尊重嵌套当然可以。事实上,与其根据 它们是什么 (页面、提供程序、管道、指令等)对事物进行分组,我更喜欢根据 对它们进行分组他们所做的就像Angular 2 style guides推荐的那样。
Folders-by-Feature Structure STYLE 04-07
Do create folders named for the feature area they represent.
Why? A developer can locate the code, identify what each file represents at a glance, the structure is as flat as it can be, and there is no repetitive nor redundant names.
Why? The LIFT guidelines are all covered.
Why? Helps reduce the app from becoming cluttered through organizing the content and keeping them aligned with the LIFT guidelines.
Why? When there are a lot of files (e.g. 10+), locating them is easier with a consistent folder structure and more difficult in a flat structure.
请记住,您必须更新所有文件和组件中的引用 templateUrl
属性(如果您 不是 使用 RC 版本)。所以
@Component({
templateUrl: 'build/pages/login/login.html',
pipes: [ ... ],
directives: [ ... ]
})
...
会变成:
@Component({
templateUrl: 'build/pages/auth/login/login.html',
pipes: [ ... ],
directives: [ ... ]
})
...