-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add an example with page loading indicator #250
Changes from 4 commits
0997b7e
4be9607
b4e3fd5
db6f328
20b284f
aef0557
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react' | ||
import Head from 'next/head' | ||
import MyLink from './MyLink' | ||
|
||
export default () => ( | ||
<div style={{ marginBottom: 20 }}> | ||
<Head> | ||
{/* Import CSS for nprogress */} | ||
<link rel='stylesheet' type='text/css' href='http://ricostacruz.com/nprogress/nprogress.css' /> | ||
</Head> | ||
|
||
<MyLink href='/'> | ||
Home | ||
</MyLink> | | ||
<MyLink href='/about'> | ||
About | ||
</MyLink> | ||
</div> | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react' | ||
import Link from 'next/link' | ||
import NProgress from 'nprogress' | ||
|
||
export default (props) => ( | ||
<Link | ||
{...props} | ||
onStart={() => NProgress.start()} | ||
onComplete={() => NProgress.done()} | ||
/> | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "with-loading", | ||
"version": "0.0.0", | ||
"description": "", | ||
"scripts": { | ||
"dev": "../../dist/bin/next" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This requires a top-level There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay that makes sense. I will right another script to play with current source code. |
||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"nprogress": "^0.2.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React, { Component } from 'react' | ||
import Header from '../components/Header' | ||
|
||
export default class About extends Component { | ||
// Add some delay | ||
static getInitialProps () { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, 500) | ||
}) | ||
} | ||
|
||
render () { | ||
return ( | ||
<div> | ||
<Header /> | ||
<p>This is about Next!</p> | ||
</div> | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
import Header from '../components/Header' | ||
|
||
export default () => ( | ||
<div> | ||
<Header /> | ||
<p>Hello Next!</p> | ||
</div> | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,15 +26,22 @@ export default class Link extends Component { | |
|
||
e.preventDefault() | ||
|
||
// getting navigation event props. | ||
const { | ||
onStart = () => null, | ||
onComplete = () => null, | ||
onError = () => null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I didn't know this is possible There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha ha. ES6 is pretty mysterious. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can do this also: onStart: theNewNameForOnStart = () => null |
||
} = this.props | ||
|
||
// straight up redirect | ||
onStart() | ||
this.context.router.push(null, href) | ||
.then((success) => { | ||
onComplete(success) | ||
if (!success) return | ||
if (scroll !== false) window.scrollTo(0, 0) | ||
}) | ||
.catch((err) => { | ||
if (this.props.onError) this.props.onError(err) | ||
}) | ||
.catch(onError) | ||
} | ||
|
||
render () { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe make a copy of this into
/static
instead? Since this ishttp
and we don't want to spam his siteThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Makes sense.