2017-03-15 14:24:54 +00:00
|
|
|
import React from 'react'
|
2017-04-10 18:35:26 +00:00
|
|
|
import PropTypes from 'prop-types'
|
2017-03-15 14:24:54 +00:00
|
|
|
import {Link} from 'next-url-prettifier'
|
|
|
|
import {Router} from '../routes'
|
|
|
|
|
|
|
|
export default class GreetingPage extends React.Component {
|
|
|
|
static getInitialProps ({query: {lang, name}}) {
|
|
|
|
return {lang, name}
|
|
|
|
}
|
|
|
|
|
2017-05-03 04:06:33 +00:00
|
|
|
renderSwitchLanguageLink () {
|
2017-03-15 14:24:54 +00:00
|
|
|
const {lang, name} = this.props
|
|
|
|
const switchLang = lang === 'fr' ? 'en' : 'fr'
|
|
|
|
return (
|
|
|
|
<Link route={Router.linkPage('greeting', {name, lang: switchLang})}>
|
|
|
|
<a>{switchLang === 'fr' ? 'Français' : 'English'}</a>
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const {lang, name} = this.props
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h1>{lang === 'fr' ? 'Bonjour' : 'Hello'} {name}</h1>
|
2017-05-03 04:06:33 +00:00
|
|
|
<div>{this.renderSwitchLanguageLink()}</div>
|
2017-03-15 14:24:54 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GreetingPage.propTypes = {
|
2017-04-10 18:35:26 +00:00
|
|
|
lang: PropTypes.string,
|
|
|
|
name: PropTypes.string
|
2017-03-15 14:24:54 +00:00
|
|
|
}
|