From 064177fbf728201795c7f98d32aa6a521e4687f5 Mon Sep 17 00:00:00 2001 From: Nick Pegg Date: Sat, 14 Oct 2017 10:15:48 -0700 Subject: [PATCH] Set titles on post mount/unmount --- src/App.js | 4 ---- src/Post.js | 8 ++++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index 19edb64..4efabdb 100644 --- a/src/App.js +++ b/src/App.js @@ -62,10 +62,6 @@ class App extends Component { ); } - - componentDidMount() { - document.title = config.title; - } } class ScrollToTop extends Component { diff --git a/src/Post.js b/src/Post.js index b3682a6..fe948ce 100644 --- a/src/Post.js +++ b/src/Post.js @@ -15,6 +15,7 @@ class Post extends Component { this.state = { post: null, + title: '', notFound: false, } } @@ -53,6 +54,11 @@ class Post extends Component { this.fetchPost(); } + componentWillUnmount() { + // Reset the document title to the default + document.title = config.title; + } + componentWillReceiveProps(props) { this.params = props.match.params; this.fetchPost(); @@ -64,6 +70,8 @@ class Post extends Component { } if (this.state.post) { + console.log(this.state.post); + document.title = `${config.title} - ${this.state.post.title}`; return (