Skip to content

Commit

Permalink
Virtual routing fix (#224)
Browse files Browse the repository at this point in the history
* run prettier

* potential fix

* fix relative paths

* switch to last index to still support relative paths on legit assets

* add test

* fix failing test
  • Loading branch information
Jasper De Moor authored and devongovett committed Jan 3, 2018
1 parent 50de97f commit e09575d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/assets/HTMLAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class HTMLAsset extends Asset {
if (node.attrs) {
for (let attr in node.attrs) {
let elements = ATTRS[attr];
// Check for virtual paths
if (node.tag === 'a' && node.attrs[attr].lastIndexOf('.') < 1) {
break;
}
if (elements && elements.includes(node.tag)) {
let assetPath = this.addURLDependency(node.attrs[attr]);
if (!isURL(assetPath)) {
Expand Down
18 changes: 18 additions & 0 deletions test/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,24 @@ describe('html', function() {
assert(html.includes('<a href="#hash_link">'));
});

it('Should detect virtual paths', async function() {
let b = await bundle(
__dirname + '/integration/html-virtualpath/index.html'
);

assertBundleTree(b, {
name: 'index.html',
assets: ['index.html'],
childBundles: [
{
type: 'html',
assets: ['other.html'],
childBundles: []
}
]
});
});

it('should not update root/main file in the bundles', async function() {
await bundle(__dirname + '/integration/html-root/index.html');

Expand Down
11 changes: 11 additions & 0 deletions test/integration/html-virtualpath/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<title>Virtual path test</title>
</head>
<body>
<a href="/somewhere">Virtual path</a>
<a href="/some/other/route">Another virtual path</a>
<a href="./other.html">A real path</a>
</body>
</html>
9 changes: 9 additions & 0 deletions test/integration/html-virtualpath/other.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
<html>
<head>
<title>Virtual path test</title>
</head>
<body>
<h1>Other page</h1>
</body>
</html>

0 comments on commit e09575d

Please sign in to comment.