We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9239524 commit b0dad3bCopy full SHA for b0dad3b
first-next/.gitignore
@@ -0,0 +1,2 @@
1
+node_modules
2
+.next
first-next/components/navBar.js
@@ -0,0 +1,24 @@
+import Link from 'next/link';
+const NavBar = () => {
3
+ const styles = {
4
+ display: "flex",
5
+ backgroundColor: "grey",
6
+ justifyContent: "space-between",
7
+ padding: "1rem"
8
+ }
9
+ return(
10
+ <div style={styles}>
11
+ <Link href="/">
12
+ <a>Home</a>
13
+ </Link>
14
+ <Link href="/about">
15
+ <a>About</a>
16
17
+ <Link href="/contact">
18
+ <a>Contact</a>
19
20
+ </div>
21
+ )
22
+}
23
+
24
+export default NavBar;
first-next/package-lock.json
first-next/package.json
@@ -0,0 +1,20 @@
+{
+ "name": "first-next",
+ "version": "1.0.0",
+ "description": "",
+ "main": "index.js",
+ "scripts": {
+ "dev": "next",
+ "build": "next build",
+ "start": "next start"
+ },
+ "keywords": [],
+ "author": "",
+ "license": "ISC",
+ "dependencies": {
+ "axios": "^0.19.0",
+ "next": "^8.1.0",
+ "react": "^16.8.6",
+ "react-dom": "^16.8.6"
first-next/pages/_app.js
@@ -0,0 +1,26 @@
+import React from 'react';
+import App, { Container } from 'next/app';
+import NavBar from '../components/navBar';
+class MyApp extends App {
+ static async getInitialProps({ Component, ctx }) {
+ let pageProps = {};
+ if (Component.getInitialProps) {
+ pageProps = await Component.getInitialProps(ctx);
+ return { pageProps };
+ render() {
+ const { Component, pageProps } = this.props;
+ return (
+ <Container>
+ <NavBar />
+ <Component {...pageProps} />
+ </Container>
+ );
25
26
+export default MyApp;
first-next/pages/about.js
@@ -0,0 +1,11 @@
+const AboutPage = () => {
+ console.log("ABOUT PAGE");
+ <div>
+ <h1>This is the about Page!!</h1>
+export default AboutPage;
first-next/pages/contact.js
@@ -0,0 +1,8 @@
+const ContactPage = () => (
+ <h1>This is the Contact Page!!</h1>
+);
+export default ContactPage;
first-next/pages/index.js
@@ -0,0 +1,34 @@
+import React, {Component} from 'react';
+import MyApp from './_app';
+import axios from 'axios';
+/*class Index extends Component{
+ static async getInitialProps(){
+ console.log("FETCH");
+ render(){
+ <h1>Index Page</h1>
+}*/
+const Index = ({posts}) => {
+ {posts.map(post => (
+ <li key={post.id}>
+ <Link href={`/post?id=${post.id}`} as={`/p/${post.id}`}><a>{post.title}</a></Link>
+ </li>
+ ))}
27
28
+Index.getInitialProps = async() => {
29
+ // https://jsonplaceholder.typicode.com/posts
30
+ const res = await axios.get("https://jsonplaceholder.typicode.com/posts")
31
+ const {data} = res;
32
+ return {posts: data}
33
34
+export default Index
first-next/pages/post.js
@@ -0,0 +1,21 @@
+// import {withRouter} from 'next/router';
+const Post = ({id, comments}) => (
+ <h1>Comments for post id: {id}</h1>
+ {comments.map(comment => (
+ <div key={comment.id}>
+ <h5>{comment.email}</h5>
+ <p>{comment.body}</p>
+Post.getInitialProps = async({query}) =>{
+ const res = await axios.get(`https://jsonplaceholder.typicode.com/comments?postId=${query.id}`)
+ return {...query, comments: data};
+// export default withRouter(Post);
+export default Post;
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments