提交 c106a1d0 编写于 作者: T Tim Neutkens 提交者: Arunoda Susiripala

Using router example improvements (#1034)

上级 4534c559
...@@ -2,30 +2,30 @@ import Router from 'next/router' ...@@ -2,30 +2,30 @@ import Router from 'next/router'
export default () => ( export default () => (
<div> <div>
<Link href='/'><a>Home</a></Link> <Link href='/'>Home</Link>
<Link href='/about'><a>About</a></Link> <Link href='/about'>About</Link>
<Link href='/error'><a>Error</a></Link> <Link href='/error'>Error</Link>
</div> </div>
) )
// typically you want to use `next/link` for this usecase // typically you want to use `next/link` for this usecase
// but this example shows how you can also access the router // but this example shows how you can also access the router
// and use it manually // and use it manually
const Link = ({ children, href }) => (
<a
href='#'
style={styles.a}
onClick={(e) => {
e.preventDefault()
Router.push(href)
}}
>
{ children }
</a>
)
const styles = { function onClickHandler (href) {
a: { return (e) => {
marginRight: 10 e.preventDefault()
Router.push(href)
} }
} }
const Link = ({ children, href }) => (
<a href='#' onClick={onClickHandler(href)}>
{children}
<style jsx>{`
a {
margin-right: 10px;
}
`}</style>
</a>
)
import React from 'react' import {Component} from 'react'
import Header from '../components/Header' import Header from '../components/Header'
import Router from 'next/router' import Router from 'next/router'
const ErrorPage = ({ aa }) => ( export default class extends Component {
<div> static getInitialProps () {
<Header /> console.log(Router.pathname)
<p>This should not be rendered via SSR</p> return {}
</div> }
)
ErrorPage.getInitialProps = () => { render () {
console.log(Router.pathname) return (
<div>
<Header />
<p>This should not be rendered via SSR</p>
</div>
)
}
} }
export default ErrorPage
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册