Answer the question
In order to leave comments, you need to log in
How to display a non-default route on the first page load?
There are such routes:
<Switch>
<Route exact path="/" component={Home}/>
<Route path="/nobel-laureates" component={About}/>
<Route path="/usage-statistics" component={History}/>
<Route component={PageNotFound}/>
</Switch>
Answer the question
In order to leave comments, you need to log in
If you meant the first visit to the site from a particular browser, then you can use localstorage to solve this problem :
import React, { Component } from 'react';
import { Redirect } from 'react-router-dom';
const isVisited = localStorage.getItem("isVisited");
if (!isVisited) {
localStorage.setItem("isVisited", true);
}
class Home extends Component {
...
render() {
if (!isVisited) return <Redirect to="/nobel-laureates" />
...
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question