0

I am new to react-router-dom and web development. I am creating a PWA on mobile browser, I could not find a way to navigate the user to exit the app like in native mobile app

what happened was the page was navigating over and over again until it hits the last stack of the history then it will close the app

I know how to listen to route changes, how do I force user to exit the app if they're in a specific route without going back to previous history

william anputra
  • 159
  • 1
  • 4
  • 12

1 Answers1

0

It depends on what do you mean by "forcing a user to exit the app"?

What is the trigger and what the effect?

Trigger can be button click for example, and effect can be redirect. let's say that the auth user on route { /app } and by clicking -


import { Redirect } from 'react-router-dom';



<button
    onClick={()=> <Redirect to="/" }
/>

But from your question it sounds like you want to use your location as trigger and do something according to that (if you don't familiar with hooks it can translated to componentDidMount/Update) -


React.useEffect(()=> {
       if (props.location.pathname === '/') {
         // Do Something here...
         }
      }  
    ,[props.location])

Here is the full { location } react-router doc https://reacttraining.com/react-router/web/api/location

Do notice that { location } have


   state: {
      [userDefined]: boolean
     }

method, maybe it will help you with user flow process

Hagai Harari
  • 2,767
  • 3
  • 11
  • 23
  • I've edited my question, basically i want to force user to exit application when they're using mobile web. currently if i press back button after navigating bunch of screens, react-router will keep re-visiting my previous history until all the the last stack then it will exit app – william anputra Oct 27 '19 at 03:30