mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 03:05:12 +00:00
Merge pull request #54 from sveltejs/preload-req
pass server request object to preload
This commit is contained in:
@@ -151,7 +151,7 @@ function get_route_handler(fn) {
|
||||
const data = { params: req.params, query: req.query };
|
||||
|
||||
if (mod.preload) {
|
||||
const promise = Promise.resolve(mod.preload(data)).then(preloaded => {
|
||||
const promise = Promise.resolve(mod.preload(req)).then(preloaded => {
|
||||
Object.assign(data, preloaded);
|
||||
return mod.render(data);
|
||||
});
|
||||
|
||||
9
test/app/routes/show-url.html
Normal file
9
test/app/routes/show-url.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<p>URL is {{url}}</p>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload({ url }) {
|
||||
return { url };
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -11,7 +11,7 @@ run('development');
|
||||
|
||||
function run(env) {
|
||||
describe(`env=${env}`, function () {
|
||||
this.timeout(5000);
|
||||
this.timeout(20000);
|
||||
|
||||
let PORT;
|
||||
let server;
|
||||
@@ -267,6 +267,14 @@ function run(env) {
|
||||
'About this site'
|
||||
);
|
||||
});
|
||||
|
||||
it('passes entire request object to preload', async () => {
|
||||
const html = await nightmare
|
||||
.goto(`${base}/show-url`)
|
||||
.evaluate(() => document.querySelector('p').innerHTML);
|
||||
|
||||
assert.equal(html, `URL is /show-url`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('headers', () => {
|
||||
|
||||
Reference in New Issue
Block a user