const Main = () => (
<div>
<Header />
<StyledMain>
<Header />
<Switch>
<Route exact path="/" component={Splash} render={()=>{alert('dd"')}}/>
<Route path="/files" component={Files} />
<Route path="/archived" component={Archived} />
<Route path="/extract/:filename" component={Extract} />
<Route path="/docs/api" component={Docs} />
</Switch>
</StyledMain>
</div>
)
In my main.js, I tried to trigger an alert whenever I enter the main route ('/')
. However, this does not work.
I also tried onEnter
, but realized that this is for the older version.
Is this the right usage?
You can put alert in your Splash component as @Tholle suggested in the comment. But with render
you can do this without using component:
const Main = () => (
<div>
<Header />
<StyledMain>
<Header />
<Switch>
<Route exact path="/" render={() => {
alert('dd"');
return <Splash />;
}
}/>
<Route path="/files" component={Files} />
<Route path="/archived" component={Archived} />
<Route path="/extract/:filename" component={Extract} />
<Route path="/docs/api" component={Docs} />
</Switch>
</StyledMain>
</div>
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With