Skip to content

Commit 1f29ef4

Browse files
author
Daniel Coulbourne
committed
Fix trailing paths in baseUrl bug.
1 parent b4ede02 commit 1f29ef4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/js/UrlBuilder.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ class UrlBuilder {
1919
if (! this.absolute)
2020
return '/';
2121

22+
if (!this.route.domain)
23+
return Ziggy.baseUrl.replace(/\/?$/, '/');
24+
2225
let host = (this.route.domain || Ziggy.baseDomain).replace(/\/+$/, '');
2326

2427
if (Ziggy.basePort && (host.replace(/\/+$/, '') === Ziggy.baseDomain.replace(/\/+$/, '')))
25-
host = host + ':' + Ziggy.basePort;
28+
host = Ziggy.baseDomain + ':' + Ziggy.basePort;
2629

2730
return Ziggy.baseProtocol + '://' + host + '/';
2831
}

tests/js/test.route.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,15 @@ describe('route()', function() {
300300
'events.venues.index',
301301
route().current()
302302
);
303-
})
303+
});
304+
305+
it('Should still work if paths are appended to baseUrl.', function() {
306+
let orgBaseUrl = Ziggy.baseUrl;
307+
global.Ziggy.baseUrl = 'http://test.thing/ab/cd/';
308+
309+
assert.equal(
310+
'http://test.thing/ab/cd/events/1/venues',
311+
route('events.venues.index', 1)
312+
);
313+
});
304314
});

0 commit comments

Comments
 (0)