Fix bug mixing props on 404
This commit is contained in:
parent
07c4de6424
commit
8099a4b45e
|
@ -3,10 +3,10 @@ import { Navbar, Header } from '.'
|
||||||
import '../stylesheets/globals.scss'
|
import '../stylesheets/globals.scss'
|
||||||
import contentStyle from '../stylesheets/content.scss'
|
import contentStyle from '../stylesheets/content.scss'
|
||||||
|
|
||||||
export const NotFoundPage = () => {
|
export const NotFoundPage = (props) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Navbar />
|
<Navbar config={props.config}/>
|
||||||
<div className={contentStyle.contentWrapper}>
|
<div className={contentStyle.contentWrapper}>
|
||||||
<Header header={'Uhm... WHAT?'} />
|
<Header header={'Uhm... WHAT?'} />
|
||||||
<div className={contentStyle.content}>
|
<div className={contentStyle.content}>
|
||||||
|
|
|
@ -1,12 +1,34 @@
|
||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { Wrapper, NotFoundPage } from '.'
|
import { Wrapper, NotFoundPage } from '.'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
import '../stylesheets/globals.scss'
|
import '../stylesheets/globals.scss'
|
||||||
|
|
||||||
export default class NotFoundWrapper extends Component {
|
export default class NotFoundWrapper extends Component {
|
||||||
|
static propTypes = {
|
||||||
|
config: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor (props) {
|
||||||
|
super(props)
|
||||||
|
|
||||||
|
let data
|
||||||
|
|
||||||
|
if (__isBrowser__) {
|
||||||
|
data = window.__INITIAL_DATA__
|
||||||
|
delete window.__INITIAL_DATA__
|
||||||
|
} else {
|
||||||
|
data = props.staticContext.context
|
||||||
|
}
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
config: data[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<NotFoundPage />
|
<NotFoundPage config={this.state.config}/>
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,9 @@ export default class MainContainer extends Component {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
if (__isBrowser__) {
|
if (__isBrowser__) {
|
||||||
data = window.__INITIAL_DATA__
|
data = window.__INITIAL_DATA__
|
||||||
console.log("window:", data)
|
|
||||||
delete window.__INITIAL_DATA__
|
delete window.__INITIAL_DATA__
|
||||||
} else {
|
} else {
|
||||||
data = props.staticContext.context
|
data = props.staticContext.context
|
||||||
console.log("StaticContext:", data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
|
|
@ -14,11 +14,9 @@ export default class PostContainer extends Component {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
if (__isBrowser__) {
|
if (__isBrowser__) {
|
||||||
data = window.__INITIAL_DATA__
|
data = window.__INITIAL_DATA__
|
||||||
console.log("window:", data)
|
|
||||||
delete window.__INITIAL_DATA__
|
delete window.__INITIAL_DATA__
|
||||||
} else {
|
} else {
|
||||||
data = props.staticContext.context
|
data = props.staticContext.context
|
||||||
console.log("StaticContext:", data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
|
|
@ -15,10 +15,19 @@ export class ServerRenderer {
|
||||||
|
|
||||||
render (req, res, next) {
|
render (req, res, next) {
|
||||||
|
|
||||||
const activeRoute = routes.find((route) => matchPath(req.url, route)) || {}
|
const activeRoute = routes.find((route) => matchPath(req.url, route)) || false
|
||||||
const head = this.head
|
const head = this.head
|
||||||
const config = this.config
|
const config = this.config
|
||||||
|
|
||||||
|
if (!activeRoute) {
|
||||||
|
const context = [{}, config]
|
||||||
|
const markup = renderToString(
|
||||||
|
<Router location={req.url} context={{ context }}>
|
||||||
|
<App/>
|
||||||
|
</Router>
|
||||||
|
)
|
||||||
|
res.status(404).send(renderFullPage(markup, head, {}, config))
|
||||||
|
} else {
|
||||||
const promise = activeRoute.getData
|
const promise = activeRoute.getData
|
||||||
? activeRoute.getData(req.path)
|
? activeRoute.getData(req.path)
|
||||||
: Promise.resolve()
|
: Promise.resolve()
|
||||||
|
@ -35,6 +44,7 @@ export class ServerRenderer {
|
||||||
}).catch(next)
|
}).catch(next)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function renderFullPage (html, head, data, config) {
|
function renderFullPage (html, head, data, config) {
|
||||||
const initialData = [data, config]
|
const initialData = [data, config]
|
||||||
|
|
Loading…
Reference in New Issue