Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual routing fix #224

Merged
merged 12 commits into from
Jan 3, 2018
4 changes: 4 additions & 0 deletions src/assets/HTMLAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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 @@ -135,6 +135,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>