diff --git a/runtime/src/server/middleware/get_page_handler.ts b/runtime/src/server/middleware/get_page_handler.ts
index fb841d8..b94d14b 100644
--- a/runtime/src/server/middleware/get_page_handler.ts
+++ b/runtime/src/server/middleware/get_page_handler.ts
@@ -177,7 +177,7 @@ export function get_page_handler(
try {
if (redirect) {
- const location = URL.resolve(req.baseUrl || '/', redirect.location);
+ const location = URL.resolve((req.baseUrl || '') + '/', redirect.location);
res.statusCode = redirect.statusCode;
res.setHeader('Location', location);
diff --git a/test/apps/with-basepath/src/routes/index.svelte b/test/apps/with-basepath/src/routes/index.svelte
index 0cc4b72..45bc3a3 100644
--- a/test/apps/with-basepath/src/routes/index.svelte
+++ b/test/apps/with-basepath/src/routes/index.svelte
@@ -1 +1,2 @@
-
Great success!
\ No newline at end of file
+Great success!
+redirect from
diff --git a/test/apps/with-basepath/src/routes/redirect-from.svelte b/test/apps/with-basepath/src/routes/redirect-from.svelte
new file mode 100644
index 0000000..45805e1
--- /dev/null
+++ b/test/apps/with-basepath/src/routes/redirect-from.svelte
@@ -0,0 +1,7 @@
+
+
+unredirected
\ No newline at end of file
diff --git a/test/apps/with-basepath/src/routes/redirect-to.svelte b/test/apps/with-basepath/src/routes/redirect-to.svelte
new file mode 100644
index 0000000..eeb0dfc
--- /dev/null
+++ b/test/apps/with-basepath/src/routes/redirect-to.svelte
@@ -0,0 +1 @@
+redirected
\ No newline at end of file
diff --git a/test/apps/with-basepath/test.ts b/test/apps/with-basepath/test.ts
index 5741d1b..a81875d 100644
--- a/test/apps/with-basepath/test.ts
+++ b/test/apps/with-basepath/test.ts
@@ -3,6 +3,8 @@ import * as puppeteer from 'puppeteer';
import * as api from '../../../api';
import { walk } from '../../utils';
import { AppRunner } from '../AppRunner';
+import { wait } from '../../utils';
+
describe('with-basepath', function() {
this.timeout(10000);
@@ -11,6 +13,11 @@ describe('with-basepath', function() {
let page: puppeteer.Page;
let base: string;
+ // helpers
+ let start: () => Promise;
+ let prefetchRoutes: () => Promise;
+ let title: () => Promise;
+
// hooks
before(async () => {
await api.build({ cwd: __dirname });
@@ -21,7 +28,7 @@ describe('with-basepath', function() {
});
runner = new AppRunner(__dirname, '__sapper__/build/server/server.js');
- ({ base, page } = await runner.start());
+ ({ base, start, page, prefetchRoutes, title } = await runner.start());
});
after(() => runner.end());
@@ -56,8 +63,43 @@ describe('with-basepath', function() {
assert.deepEqual(non_client_assets, [
'custom-basepath/global.css',
'custom-basepath/index.html',
+ 'custom-basepath/redirect-from/index.html',
+ 'custom-basepath/redirect-to/index.html',
'custom-basepath/service-worker-index.html',
'custom-basepath/service-worker.js'
]);
});
+
+ it('redirects on server', async () => {
+ await page.goto(`${base}/custom-basepath/redirect-from`);
+
+ assert.equal(
+ page.url(),
+ `${base}/custom-basepath/redirect-to`
+ );
+
+ assert.equal(
+ await title(),
+ 'redirected'
+ );
+ });
+
+ it('redirects in client', async () => {
+ await page.goto(`${base}/custom-basepath`);
+ await start();
+ await prefetchRoutes();
+
+ await page.click('[href="redirect-from"]');
+ await wait(50);
+
+ assert.equal(
+ page.url(),
+ `${base}/custom-basepath/redirect-to`
+ );
+
+ assert.equal(
+ await title(),
+ 'redirected'
+ );
+ });
});
\ No newline at end of file