Могут ли страницы ionic2 поддерживать вложенную структуру каталогов?
Я вижу pages
Каталог многих проектов Ionic 2 представляет собой плоскую структуру, как показано ниже (если мы используем команду ее генерации, сгенерированная структура каталога будет плоской).
например
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's pages
поддержать это? Тот же вопрос к другим каталогам вроде providers
а также pipes
,
2 ответа
Конечно, это так. In fact, instead of grouping things in terms of what they are (pages, providers, pipes, directives, and so on) I do prefer to group them in terms of what they do just like https://angular.io/styleguide recommends.
Folders-by-Feature Structure STYLE 04-07
Do create folders named for the feature area they represent.
Зачем? 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.
Зачем? The LIFT guidelines are all covered.
Зачем? Helps reduce the app from becoming cluttered through organizing the content and keeping them aligned with the LIFT guidelines.
Зачем? When there are a lot of files (eg 10+), locating them is easier with a consistent folder structure and more difficult in a flat structure.
Just keep in mind that you'll have to update the references both in all the files and also in the components templateUrl
property (if you're not using the RC version). Так
@Component({
templateUrl: 'build/pages/login/login.html',
pipes: [ ... ],
directives: [ ... ]
})
...
превратится в:
@Component({
templateUrl: 'build/pages/auth/login/login.html',
pipes: [ ... ],
directives: [ ... ]
})
...
Да. Оно делает.
Вы просто должны соблюдать вложенность при импорте страниц для вашего NgModule в src/app/app.module.ts