From 93b36b3ed845cf09b7f5f79acc1e20ebebda2473 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 20 Jul 2017 02:37:40 +0200 Subject: [PATCH] build: no longer fallback to index.html file (#5879) --- tools/gulp/util/task_helpers.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/gulp/util/task_helpers.ts b/tools/gulp/util/task_helpers.ts index 10407981de2..b9d6edbc5b7 100644 --- a/tools/gulp/util/task_helpers.ts +++ b/tools/gulp/util/task_helpers.ts @@ -148,12 +148,17 @@ export function serverTask(packagePath: string, livereload = true) { root: projectDir, livereload: livereload, port: 4200, - fallback: path.join(packagePath, 'index.html'), middleware: () => { return [httpRewrite.getMiddleware([ + // Rewrite the node_modules/ and dist/ folder to the real paths. This is a trick to + // avoid that those folders will be rewritten to the specified package path. { from: '^/node_modules/(.*)$', to: '/node_modules/$1' }, { from: '^/dist/(.*)$', to: '/dist/$1' }, - { from: '^(.*)$', to: `/${relativePath}/$1` } + // Rewrite every path that doesn't point to a specific file to the index.html file. + // This is necessary for Angular's routing using the HTML5 History API. + { from: '^/[^.]+$', to: `/${relativePath}/index.html`}, + // Rewrite any path that didn't match a pattern before to the specified package path. + { from: '^(.*)$', to: `/${relativePath}/$1` }, ])]; } });