docs(new page): new page docs and typos fixes

This commit is contained in:
nixa 2016-05-25 14:35:19 +03:00
parent d20b9a94f0
commit d69937ad53
9 changed files with 59 additions and 57 deletions

View file

@ -6,63 +6,59 @@ group: Customization
template: article.jade
---
Blur admin uses [Angular UI router](https://github.com/angular-ui/ui-router) for navigation.
That means to create new page you need to basically configure `ui-router` state.
ng2-admin uses [Angular Router](https://angular.io/docs/ts/latest/guide/router-deprecated.html) for navigation.
Currently this version of the router is deprecated and we are going to move on to a new version once it's stable.
We strongly recommend to follow pages structure in your application.
If it doesn't fit your needs please create a GitHub issue and tell us why. We would be glad to discuss.
Also we recommend to put pages to separate modules.
This will allow you to easily switch off some pages in the future if needed.
Basically any page is just a usual Angular 2 Component with some routes defined for it.
## Page creation example
0) Let's assume we want to create a blank page with title 'My New Page'
1) Let's assume we want to create a blank page with title 'My New Page'
<br><br>
1) Let's Create a new directory to contain our new page inside of `src/app/pages`. Let's call this directory `myNewPage`.
2) Let's Create a new directory to contain our new page inside of `src/app/pages`. Let's call this directory `new`.
<br><br>
2) Then let's create blank angular module to contain our page called 'myNewPage.module.js' inside of `src/app/pages/myNewPage`:
3) Then let's create blank angular component to contain our page called 'new.component.module.js' inside of `src/app/pages/new`:
```javascript
(function () {
'use strict';
import {Component} from '@angular/core';
angular.module('BlurAdmin.pages.myNewPage', [])
.config(routeConfig);
@Component({
selector: 'new',
pipes: [],
providers: [],
styles: [],
template: `<strong>My page content here</strong>`
})
export class New {
/** @ngInject */
function routeConfig() {
constructor() {
}
})();
}
```
This will create a simple Angular 2 component, for more detail please check out [official Angular 2 documentation](https://angular.io/docs/ts/latest/guide/displaying-data.html).
<br><br>
3) Then let's create empty html file called `my-new-page.html` inside of `src/app/pages/myNewPage`.
4) Lastly let's create ui router state for this page. To do this we need to modify module.js file we created on step 2:
4) Last thing we need to do is to define a Router configuration in a parent component, in our case in Pages component `src/app/pages/pages.component.ts`:
```javascript
(function () {
'use strict';
angular.module('BlurAdmin.pages.myNewPage', [])
.config(routeConfig);
/** @ngInject */
function routeConfig($stateProvider) {
$stateProvider
.state('myNewPage', {
url: '/myNewPage',
templateUrl: 'app/pages/myNewPage/my-new-page.html',
title: 'My New Page',
sidebarMeta: {
order: 800,
},
});
@RouteConfig([
// ... some routes here
{
name: 'New',
component: New,
path: '/new',
}
})();
])
export class Pages {
}
```
<br><br>
That's it! Your can now open your new page either from sidebar or through hash URL.
And that's it! now your page should be available by the following url [http://localhost:3000/#/pages/new](http://localhost:3000/#/pages/new).
If you want to add a link to your page into Sidebar, please look at the [following article](/ng2-admin/articles/015-sidebar/).