diff --git a/templates/AngularSpa/ClientApp/app/app.module.browser.ts b/templates/AngularSpa/ClientApp/app/app.module.browser.ts index 7e71ca9..03104b4 100644 --- a/templates/AngularSpa/ClientApp/app/app.module.browser.ts +++ b/templates/AngularSpa/ClientApp/app/app.module.browser.ts @@ -10,12 +10,12 @@ import { AppComponent } from './components/app/app.component'; AppModuleShared ], providers: [ - { provide: 'ORIGIN_URL', useFactory: getOriginUrl } + { provide: 'BASE_URL', useFactory: getBaseUrl } ] }) export class AppModule { } -export function getOriginUrl() { - return location.origin; +export function getBaseUrl() { + return document.getElementsByTagName('base')[0].href; } diff --git a/templates/AngularSpa/ClientApp/app/components/fetchdata/fetchdata.component.ts b/templates/AngularSpa/ClientApp/app/components/fetchdata/fetchdata.component.ts index 6296925..a4c06f4 100644 --- a/templates/AngularSpa/ClientApp/app/components/fetchdata/fetchdata.component.ts +++ b/templates/AngularSpa/ClientApp/app/components/fetchdata/fetchdata.component.ts @@ -8,8 +8,8 @@ import { Http } from '@angular/http'; export class FetchDataComponent { public forecasts: WeatherForecast[]; - constructor(http: Http, @Inject('ORIGIN_URL') originUrl: string) { - http.get(originUrl + '/api/SampleData/WeatherForecasts').subscribe(result => { + constructor(http: Http, @Inject('BASE_URL') baseUrl: string) { + http.get(baseUrl + 'api/SampleData/WeatherForecasts').subscribe(result => { this.forecasts = result.json() as WeatherForecast[]; }, error => console.error(error)); } diff --git a/templates/AngularSpa/ClientApp/boot.server.ts b/templates/AngularSpa/ClientApp/boot.server.ts index 08474cf..851e137 100644 --- a/templates/AngularSpa/ClientApp/boot.server.ts +++ b/templates/AngularSpa/ClientApp/boot.server.ts @@ -1,6 +1,7 @@ import 'reflect-metadata'; import 'zone.js'; import 'rxjs/add/operator/first'; +import { APP_BASE_HREF } from '@angular/common'; import { enableProdMode, ApplicationRef, NgZone, ValueProvider } from '@angular/core'; import { platformDynamicServer, PlatformState, INITIAL_CONFIG } from '@angular/platform-server'; import { createServerRenderer, RenderResult } from 'aspnet-prerendering'; @@ -11,7 +12,8 @@ enableProdMode(); export default createServerRenderer(params => { const providers = [ { provide: INITIAL_CONFIG, useValue: { document: '', url: params.url } }, - { provide: 'ORIGIN_URL', useValue: params.origin } + { provide: APP_BASE_HREF, useValue: params.baseUrl }, + { provide: 'BASE_URL', useValue: params.origin + params.baseUrl }, ]; return platformDynamicServer(providers).bootstrapModule(AppModule).then(moduleRef => { diff --git a/templates/AngularSpa/webpack.config.js b/templates/AngularSpa/webpack.config.js index fd1ff6e..85e238d 100644 --- a/templates/AngularSpa/webpack.config.js +++ b/templates/AngularSpa/webpack.config.js @@ -13,7 +13,7 @@ module.exports = (env) => { resolve: { extensions: [ '.js', '.ts' ] }, output: { filename: '[name].js', - publicPath: '/dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix + publicPath: 'dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix }, module: { rules: [ diff --git a/templates/AngularSpa/webpack.config.vendor.js b/templates/AngularSpa/webpack.config.vendor.js index ed7fa93..36e4386 100644 --- a/templates/AngularSpa/webpack.config.vendor.js +++ b/templates/AngularSpa/webpack.config.vendor.js @@ -36,7 +36,7 @@ module.exports = (env) => { ] }, output: { - publicPath: '/dist/', + publicPath: 'dist/', filename: '[name].js', library: '[name]_[hash]' }, diff --git a/templates/AureliaSpa/ClientApp/app/components/fetchdata/fetchdata.ts b/templates/AureliaSpa/ClientApp/app/components/fetchdata/fetchdata.ts index ff86025..6cd72ac 100644 --- a/templates/AureliaSpa/ClientApp/app/components/fetchdata/fetchdata.ts +++ b/templates/AureliaSpa/ClientApp/app/components/fetchdata/fetchdata.ts @@ -6,7 +6,7 @@ export class Fetchdata { public forecasts: WeatherForecast[]; constructor(http: HttpClient) { - http.fetch('/api/SampleData/WeatherForecasts') + http.fetch('api/SampleData/WeatherForecasts') .then(result => result.json() as Promise) .then(data => { this.forecasts = data; diff --git a/templates/AureliaSpa/ClientApp/boot.ts b/templates/AureliaSpa/ClientApp/boot.ts index 5c9e2fd..053b9c3 100644 --- a/templates/AureliaSpa/ClientApp/boot.ts +++ b/templates/AureliaSpa/ClientApp/boot.ts @@ -1,5 +1,6 @@ import 'isomorphic-fetch'; import { Aurelia, PLATFORM } from 'aurelia-framework'; +import { HttpClient } from 'aurelia-fetch-client'; import 'bootstrap/dist/css/bootstrap.css'; import 'bootstrap'; declare const IS_DEV_BUILD: boolean; // The value is supplied by Webpack during the build @@ -11,5 +12,10 @@ export function configure(aurelia: Aurelia) { aurelia.use.developmentLogging(); } + new HttpClient().configure(config => { + const baseUrl = document.getElementsByTagName('base')[0].href; + config.withBaseUrl(baseUrl); + }); + aurelia.start().then(() => aurelia.setRoot(PLATFORM.moduleName('app/components/app/app'))); } diff --git a/templates/AureliaSpa/webpack.config.js b/templates/AureliaSpa/webpack.config.js index 4ddc35c..5ff94d0 100644 --- a/templates/AureliaSpa/webpack.config.js +++ b/templates/AureliaSpa/webpack.config.js @@ -14,7 +14,7 @@ module.exports = (env) => { }, output: { path: path.resolve(bundleOutputDir), - publicPath: '/dist/', + publicPath: 'dist/', filename: '[name].js' }, module: { diff --git a/templates/AureliaSpa/webpack.config.vendor.js b/templates/AureliaSpa/webpack.config.vendor.js index 9625a31..1dc579c 100644 --- a/templates/AureliaSpa/webpack.config.vendor.js +++ b/templates/AureliaSpa/webpack.config.vendor.js @@ -38,7 +38,7 @@ module.exports = ({ prod } = {}) => { }, output: { path: path.join(__dirname, 'wwwroot', 'dist'), - publicPath: '/dist/', + publicPath: 'dist/', filename: '[name].js', library: '[name]_[hash]', }, diff --git a/templates/KnockoutSpa/ClientApp/boot.ts b/templates/KnockoutSpa/ClientApp/boot.ts index 143e8e5..b8da1dd 100644 --- a/templates/KnockoutSpa/ClientApp/boot.ts +++ b/templates/KnockoutSpa/ClientApp/boot.ts @@ -4,12 +4,14 @@ import * as ko from 'knockout'; import './webpack-component-loader'; import AppRootComponent from './components/app-root/app-root'; const createHistory = require('history').createBrowserHistory; +const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href'); +const basename = baseUrl.substring(0, baseUrl.length - 1); // History component needs no trailing slash // Load and register the component ko.components.register('app-root', AppRootComponent); // Tell Knockout to start up an instance of your application -ko.applyBindings({ history: createHistory() }); +ko.applyBindings({ history: createHistory({ basename }), basename }); // Basic hot reloading support. Automatically reloads and restarts the Knockout app each time // you modify source files. This will not preserve any application state other than the URL. diff --git a/templates/KnockoutSpa/ClientApp/components/app-root/app-root.html b/templates/KnockoutSpa/ClientApp/components/app-root/app-root.html index f1f11b4..88e345b 100644 --- a/templates/KnockoutSpa/ClientApp/components/app-root/app-root.html +++ b/templates/KnockoutSpa/ClientApp/components/app-root/app-root.html @@ -1,7 +1,7 @@
- +
diff --git a/templates/KnockoutSpa/ClientApp/components/app-root/app-root.ts b/templates/KnockoutSpa/ClientApp/components/app-root/app-root.ts index af9062c..2ca1bfe 100644 --- a/templates/KnockoutSpa/ClientApp/components/app-root/app-root.ts +++ b/templates/KnockoutSpa/ClientApp/components/app-root/app-root.ts @@ -12,12 +12,12 @@ const routes: Route[] = [ class AppRootViewModel { public route: KnockoutObservable; - private _router: Router; + public router: Router; - constructor(params: { history: History.History }) { + constructor(params: { history: History.History, basename: string }) { // Activate the client-side router - this._router = new Router(params.history, routes) - this.route = this._router.currentRoute; + this.router = new Router(params.history, routes, params.basename); + this.route = this.router.currentRoute; // Load and register all the KO components needed to handle the routes // The optional 'bundle-loader?lazy!' prefix is a Webpack feature that causes the referenced modules @@ -32,7 +32,7 @@ class AppRootViewModel { // To support hot module replacement, this method unregisters the router and KO components. // In production scenarios where hot module replacement is disabled, this would not be invoked. public dispose() { - this._router.dispose(); + this.router.dispose(); // TODO: Need a better API for this Object.getOwnPropertyNames((ko).components._allRegisteredComponents).forEach(componentName => { diff --git a/templates/KnockoutSpa/ClientApp/components/fetch-data/fetch-data.ts b/templates/KnockoutSpa/ClientApp/components/fetch-data/fetch-data.ts index 9576d66..b053890 100644 --- a/templates/KnockoutSpa/ClientApp/components/fetch-data/fetch-data.ts +++ b/templates/KnockoutSpa/ClientApp/components/fetch-data/fetch-data.ts @@ -12,7 +12,7 @@ class FetchDataViewModel { public forecasts = ko.observableArray(); constructor() { - fetch('/api/SampleData/WeatherForecasts') + fetch('api/SampleData/WeatherForecasts') .then(response => response.json() as Promise) .then(data => { this.forecasts(data); diff --git a/templates/KnockoutSpa/ClientApp/components/nav-menu/nav-menu.html b/templates/KnockoutSpa/ClientApp/components/nav-menu/nav-menu.html index 0bfd32c..f053cef 100644 --- a/templates/KnockoutSpa/ClientApp/components/nav-menu/nav-menu.html +++ b/templates/KnockoutSpa/ClientApp/components/nav-menu/nav-menu.html @@ -13,17 +13,17 @@