Skip to content

Commit

Permalink
feat(layouts): add page content for error pages (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
mercs600 committed Mar 21, 2020
1 parent 657b640 commit 68527a6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
6 changes: 6 additions & 0 deletions example/layouts/error.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<template>
<div>
<h1>ERROR PAGE {{ error.statusCode }}</h1>
<be-dynamic
v-if="error.ssr"
:page="error.ssr.pageContent.page"
:content="error.ssr.pageContent.content"
:type="error.ssr.backendLayout"
/>
</div>
</template>
<script>
Expand Down
37 changes: 24 additions & 13 deletions lib/templates/middleware/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,37 @@ import { isDynamicRoute } from '~typo3/lib/route'
import { SET_PAGE } from '~typo3/store/mutation-types'
import { getBackendLayout, getFrontendLayout } from '~typo3/lib/layouts'

const setContext = (context, response) => {
if (response.data && response.data.page) {
context.layout = getFrontendLayout(
response.data.page.appearance.layout,
context.app.$typo3.options.layouts
)
context.backendLayout = getBackendLayout(
context.app.components,
response.data.page.appearance.backendLayout
)
context.pageContent = response.data
context.store.commit(SET_PAGE, response.data)
}
}

middleware.typo3Context = function(context) {
const path = context.route.fullPath || context.route.path
if (isDynamicRoute(context.route)) {
return context.app.$typo3.api
.getPage(path)
.then(resp => {
context.layout = getFrontendLayout(
resp.data.page.appearance.layout,
context.app.$typo3.options.layouts
)
context.backendLayout = getBackendLayout(
context.app.components,
resp.data.page.appearance.backendLayout
)
context.pageContent = resp.data
context.store.commit(SET_PAGE, resp.data)
})
.then(response => setContext(context, response))
.catch(error => {
context.errorResponse = error.response
setContext(context, error.response)
return context.error({
ssr: context.pageContent
? {
layout: context.layout,
backendLayout: context.backendLayout,
pageContent: context.pageContent
}
: null,
message: error.response.message,
statusCode: error.response.status
})
Expand Down

0 comments on commit 68527a6

Please sign in to comment.