Skip to main content

The Complete React Guide by Max - Section 11: Multi-Page-Feeling in a Single-Page-App: Routing

 203. Extracting Route Parameters

componentDidMount() {
    axios.get("/posts/" + this.props.match.params.id).then((response) => {

Changed from componentDidMount to componentDidMount as we are not updating this. this.props.match.params.id successfully passing route parameters and extracting them 


205. Using switch to load a single route

<Route path="/" exact component={Posts} />
<Switch>
<Route path="/new-post" component={NewPost} />
<Route path="/:id" exact component={FullPost} />
</Switch>

<Switch> to ensure that only one route gets loaded at a time.


206. Navigating programmatically 

postSelectedHandler = (id) => {
//this.props.history.push({ pathname: "/" + id });
this.props.history.push("/" + id);
};

navigation is about a stack of pages. push() allows you to push a new page onto the stack so back and forward buttons work


207. Additional info Regarding Active link

exact is set to treat as active. 


208. Understanding Nested Routes

<Route path={this.props.match.url + "/:id"} exact component={FullPost} />


209. Creating Dynamic Nested Routes 

Important to fix match.params.id 

(this.state.loadedPost && this.state.loadedPost.id !== +this.props.match.params.id)

need to handle change in compoenetDidUpdate if component is already loaded through routing 

componentDidUpdate() {
this.loadData();
}


210. Redirecting Requests 

<Redirect from="/" to="/posts" />


211. Conditional Redirects 

let redirect = null;
if (this.state.submitted) {
redirect = <Redirect to="/posts" />;
}


212. Using the history prop to Redirect (Replace)

this.props.history.replace("/posts");

replace() or push(). new post was replaced on a stack of pages. 



213. Working with Guards

{this.state.auth ? (
<Route path="/new-post" component={NewPost} />
) : null}


214. Handling the 404 Case (Unknown Routes)

<Route render={() => <h1>Not Found</h1>} />
{/* <Redirect from="/" to="/posts" /> */}

2nd line won't work together due to from='/' as it catches all routes 


215. Loading Routes lazily 

load asychronously only when its needed

216.


217.


218.


219. Useful Links


Assignment 





















































Comments

Popular posts from this blog

[BAEKJOON Online Judge + Node.js] 2292: Honeycomb

  I did't use while loop that much so didn't come up what to do. While loop create a loop that execute a specific statement. So, the main point of this problem is "prevNum + max * 6" input = 13, output = 3 https://www.acmicpc.net/problem/2292 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while const input = require ( "fs" ). readFileSync ( "/dev/stdin" ). toString () ; let count = 1 ; let max = 1 ; // set the range while (max < input) { max += count * 6 ; count ++ ; } console . log (count) ; // prevNum + count * 6 // 1 so +6 every loop! // 2 - 7, 5 // 8 - 19, 11 // 20 - 37, 17 // 38 - 61, 23

FE WebDev Routine Training Feb 09, 2021

 FE WebDev Routine Training Feb 09, 2021  A lot of things to do. DO FUCKING FOCUS!!!  Coding test - codewar 1 Kakao 2021 No.1 CSS - grid/ SCSS and Cloning(besthorrorscenes.com) JS - for of loop/  Sec9/ DOM array methods toy project React -   A bit of Yelp Portfolio -  List the 100JS projects Job hunting -  NAVER Finance(on 10th) Karrot for  internship  Apply SW maestro