Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+ [feat] add the location strategy option #265

Merged
merged 7 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'" %> }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hash is the default here, so no need to be told explicitely for this use case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've worried about if ionic team change the default. So I prefer to not rely on its default value.

<% } -%>
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