Skip to content

Commit

Permalink
+ [feat] add the location strategy option (#265)
Browse files Browse the repository at this point in the history
* + [feat] add location strategy option

* * [bug] forget add quote to location

* * update @angular/cli@1.7.2 to avoid the material compiler error

* * do not import LocationStrategy for inonic ui

* * use the location-strategy option and hidden the prompt.
  • Loading branch information
snowyu authored and sinedied committed Mar 5, 2018
1 parent 1408bc8 commit 50fa8a8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class NgxGenerator extends Generator {
this.props = {ui: 'raw'};
}

if (this.options['location-strategy']) {
this.props = this.config.get('props') || {};
this.props.location = this.options['location-strategy'];
}

// Updating
let fromVersion = null;

Expand Down
7 changes: 7 additions & 0 deletions generators/app/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,12 @@
"required": false,
"description": "Do not use any UI library",
"defaults": false
},
{
"name": "location-strategy",
"type": "String",
"required": false,
"description": "The location strategies in angular router: path/hash",
"defaults": "path"
}
]
22 changes: 21 additions & 1 deletion generators/app/templates/src/app/_app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
<% } else { -%>
import { NgModule } from '@angular/core';
import {
LocationStrategy,
<% if (props.location === 'hash') { -%>
HashLocationStrategy,
<% } else { -%>
PathLocationStrategy,
<% } -%>
} from '@angular/common';
<% } -%>
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
Expand Down Expand Up @@ -54,7 +62,7 @@ import { AppRoutingModule } from './app-routing.module';
<% } else if (props.ui === 'bootstrap') { -%>
NgbModule.forRoot(),
<% } else if (props.ui === 'ionic') { -%>
IonicModule.forRoot(AppComponent, { locationStrategy: 'path' }),
IonicModule.forRoot(AppComponent, { locationStrategy: <%- props.location === 'hash' ? "'hash'": "'path'" %> }),
<% } -%>
CoreModule,
SharedModule,
Expand All @@ -69,6 +77,18 @@ import { AppRoutingModule } from './app-routing.module';
],
declarations: [AppComponent],
providers: [
<% if (props.ui !== 'ionic') { -%>
{
provide: LocationStrategy,
<% if (props.location === 'hash') { -%>
// This strategy with base-href './' allow to move the app to any subsite and works
useClass: HashLocationStrategy
<% } else { -%>
// Only if passed the --base-href argument at build & the server has url rewrite to index.html
useClass: PathLocationStrategy
<% } -%>
},
<% } -%>
<% if (props.ui === 'ionic') { -%>
<% if (props.target.includes('cordova')) { -%>
{ provide: ErrorHandler, useClass: IonicErrorHandler },
Expand Down

0 comments on commit 50fa8a8

Please sign in to comment.