mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-22 15:15:19 +00:00
detach SSRd <head> contents
This commit is contained in:
@@ -64,11 +64,12 @@ module.exports = function connect(opts) {
|
||||
let data = { params: req.params, query: req.query };
|
||||
if (mod.default.preload) data = Object.assign(data, await mod.default.preload(data));
|
||||
|
||||
const { html, css } = mod.default.render(data);
|
||||
const { html, head, css } = mod.default.render(data);
|
||||
|
||||
const page = templates.render(200, {
|
||||
main,
|
||||
html,
|
||||
head: `<noscript id='sapper-head-start'></noscript>${head}<noscript id='sapper-head-end'></noscript>`,
|
||||
styles: (css && css.code ? `<style>${css.code}</style>` : '')
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const router = {
|
||||
const app = {
|
||||
init(callback) {
|
||||
window.addEventListener('click', event => {
|
||||
let a = event.target;
|
||||
@@ -19,6 +19,4 @@ const router = {
|
||||
}
|
||||
};
|
||||
|
||||
window.router = router;
|
||||
|
||||
export default router;
|
||||
export default app;
|
||||
@@ -1,9 +1,10 @@
|
||||
import router from 'sapper/runtime/router.js';
|
||||
import app from 'sapper/runtime/app.js';
|
||||
import { detachNode } from 'svelte/shared.js';
|
||||
|
||||
const target = document.querySelector('__selector__');
|
||||
let component;
|
||||
|
||||
router.init(url => {
|
||||
app.init(url => {
|
||||
if (url.origin !== window.location.origin) return;
|
||||
|
||||
let match;
|
||||
@@ -19,6 +20,16 @@ router.init(url => {
|
||||
if (component) {
|
||||
component.destroy();
|
||||
} else {
|
||||
// remove SSR'd <head> contents
|
||||
const start = document.querySelector('#sapper-head-start');
|
||||
let end = document.querySelector('#sapper-head-end');
|
||||
|
||||
if (start && end) {
|
||||
while (start.nextSibling !== end) detachNode(start.nextSibling);
|
||||
detachNode(start);
|
||||
detachNode(end);
|
||||
}
|
||||
|
||||
target.innerHTML = '';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user