项目作者: francescodist

项目描述 :
Template for Angular Material 8 with Login and SideNav
高级语言: TypeScript
项目地址: git://github.com/francescodist/matFortyTwo.git
创建时间: 2019-05-01T15:05:39Z
项目社区:https://github.com/francescodist/matFortyTwo

开源协议:

下载


MatFortyTwo

The answer to everything (well… almost) that’s Angular Material

Description

MatFortyTwo is a boilerplate for Angular Material that promotes a design
with two separate navigation stacks. One at root level and one (with title
and sidenav) accessible only after having logged in. It also packs a lot
of perks to help you kickstart your Angular project in a matter of minutes!

Angular CLI Version: 8.0.1 \
Angular Material Version: 8.0.0

Perks

  • Navigation Flow and guarded access for Pages
  • Script to generate root/sidenav page
  • Theming
  • Complete authorization flow with Token
  • Lazy Loaded Pages
  • Pre-built responsive Sidenav Component and Login Page
  • Linting with pre-commit check
  • Many more coming soon…

You can just focus on the content of your application! If you use the
built-in scripts for page generation, everything else will be taken care
of for you!

Script Usage

This will generate a new component (PageNamePageComponent) with routing in
src/app/pages/page-name

!!!Use kebab-case for page names!!!

  1. # GENERATE A ROOT PAGE
  2. npm run genpage -- -r page-name
  3. # GENERATE A SIDENAV PAGE
  4. npm run genpage -- -n page-name
  5. # GENERATE A PAGE THAT'S BOTH ROOT AND SIDENAV
  6. npm run genpage -- -rn page-name
  7. # GENERATE A CHILD SIDENAV PAGE
  8. npm run genpage -- -c page-name
  9. # GENERATE A SIDENAV PAGE WITH SPECIFIC ICON NAME (mat-icon)
  10. # (The icon will be in the sidenav next to the tile of the page)
  11. npm run genpage -- -n page-name -i home

If you want to edit further, you can find the generated routes in:\
src/app/app-routing.module.ts - Root Page \
src/app/nav-routing.ts - SideNav Page

About Child Sidenav Pages

Child Sidenav Pages are pages that are meant to be accessible only
through navigation from a sidenav page. They will not appear in the list
in the sidenav menu and will show a back button in the top bar that
will send you to the parent page when clicked. They will also automatically
highlight the parent item in the sidenav menu, even when accessed directly
through URL.


Since children pages are always relative to a parent page, some additional
configuration will be needed after running the script. The child route
needs to be defined in the parent page’s routing module. The data
property for this new route needs to contain a title and a “isChild”
attribute set to true.


Let’s have a look at a practical example:

We have a sidenav page called “home-page” and we want a child page
named “child-page” that we can access from “home-page” instead of
the sidenav menu.


First, we run the script for child sidenav pages

  1. npm run genpage -- -c child

Now that the page has been generated, we can see that it is not present
in the sidenav menu list ( just as we expected ).


Next step is to add the child route in the “home-page” routing module



This is how the routes in your home-page-routing.module should look like:

  1. const routes: Routes = [
  2. {
  3. path: '',
  4. data: { shouldReuse: true, key: 'home' },
  5. component: HomePageComponent,
  6. },
  7. ]

Simply add the new child route to this file like this:

  1. const routes: Routes = [
  2. {
  3. path: '',
  4. data: { shouldReuse: true, key: 'home' },
  5. component: HomePageComponent,
  6. },
  7. {
  8. path: 'child',
  9. loadChildren: () =>
  10. import('../child-page/child-page.module').then(
  11. m => m.ChildPageModule,
  12. ),
  13. data: { title: 'Child', isChild: true },
  14. },
  15. ]

Now, if you navigate to YOUR_NAV_URL /home/child
you should see a page with the title “Child”, a back button that will
redirect you to the home page and the child component being correctly
rendered in the content container below.


NB: It is of course possible to define a page that’s the child of a child,
but it’s essential to avoid to create any loop to previous pages
because that will break your application.

It’s also not necessary to define the isChild attribute for children
at a deeper level, as this information will be passed through by the
first one.

Theming

Simply go to src/variables.scss and change the values for
font, primary, accent or warn color.

Screenshots

Login Page

Login Page

Sidenav Page

Sidenav Page

Different Theme

  1. variables.scss
  2. - $my-app-primary: mat-palette($mat-red);
  3. + $my-app-primary: mat-palette($mat-blue);

Blue Login Page
Blue Sidenav Page