mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
db7c286740
* [example] with pretty url routing * use single quotes even in React components * improve Link import
35 lines
842 B
JavaScript
35 lines
842 B
JavaScript
import React from 'react'
|
|
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}
|
|
}
|
|
|
|
renderSwitchLangageLink () {
|
|
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>
|
|
<div>{this.renderSwitchLangageLink()}</div>
|
|
</div>
|
|
)
|
|
}
|
|
}
|
|
|
|
GreetingPage.propTypes = {
|
|
lang: React.PropTypes.string,
|
|
name: React.PropTypes.string
|
|
}
|