11.24 Redirecting Requests
Blog.js
Blog.js
// import axios from "axios";
import React, { Component } from "react";
import { NavLink, Redirect, Route, Switch } from "react-router-dom";
import "./Blog.css";
import NewPost from "./NewPost/NewPost";
import Posts from "./Posts/Posts";
class Blog extends Component {
render() {
return (
<div className="Blog">
<header>
<nav>
<ul>
<li>
<NavLink
to="/posts/"
exact
activeClassName="my-active"
activeStyle={{
color: "#fa923f",
textDecoration: "underline",
}}
>
Posts
</NavLink>
</li>
<li>
<NavLink
to={{
pathname: "/new-post",
hash: "#submit",
search: "?quick-submit=true",
}}
>
New Post
</NavLink>
</li>
</ul>
</nav>
</header>
{/* <Route path="/" exact render={() => <h1>Home</h1>} />
<Route path="/" render={() => <h1>Home2</h1>} /> */}
<Switch>
<Route path="/new-post" component={NewPost} />
<Route path="/posts" component={Posts} />
<Redirect from="/" to="/posts" />
{/* <Route path="/" component={Posts} /> */}
</Switch>
</div>
);
}
}
export default Blog;