implement this.redirect in preload (#83)

This commit is contained in:
Rich Harris
2018-02-17 22:56:47 -05:00
parent f8ea9ebda1
commit bff6f550be
7 changed files with 71 additions and 80 deletions

View File

@@ -3,6 +3,7 @@
<li><a href='/'>home</a></li>
<li><a href='/about'>about</a></li>
<li><a href='/slow-preload'>slow preload</a></li>
<li><a href='/redirect-from'>redirect</a></li>
<li><a rel=prefetch class='{{page === "blog" ? "selected" : ""}}' href='/blog'>blog</a></li>
</ul>
</nav>

View File

@@ -0,0 +1,7 @@
<script>
export default {
preload() {
this.redirect(301, '/redirect-to');
}
};
</script>

View File

@@ -0,0 +1 @@
<h1>redirected</h1>

View File

@@ -297,6 +297,33 @@ function run(env) {
assert.ok(matches);
});
});
it('redirects on server', () => {
return nightmare.goto(`${base}/redirect-from`)
.path()
.then(path => {
assert.equal(path, '/redirect-to');
})
.then(() => nightmare.page.title())
.then(title => {
assert.equal(title, 'redirected');
});
});
it('redirects on client', () => {
return nightmare.goto(base)
.wait('[href="/redirect-from"]')
.click('[href="/redirect-from"]')
.wait(200)
.path()
.then(path => {
assert.equal(path, '/redirect-to');
})
.then(() => nightmare.page.title())
.then(title => {
assert.equal(title, 'redirected');
});
});
});
describe('headers', () => {