Print
Category: Technology
Hits: 2970

1) What is the use of 'exact' keyword in <Route> ?

    Let we assume there are 2 routes defined in following way

   <Route path="/order" component={OrderMaster}/>

   <Route path="/order/details" component={OrderDetail}/>

    React always do URL partial mapping thus URL

    "http://IP:port/order" will match and load "OrderMaster" component (its good)

    http://IP:port/order/details" is partially matches with "/order" and again same "OrderMaster" component loaded instead "OrderDetail"

    Here, "exact" get into picture to disable the partial URL mapping behaviour by React

   <Route path="/order" component={OrderMaster} exact />

   <Route path="/order/details" component={OrderDetail} exact />

 

2) How to manage idle time out ? like session time out in .NET?

    Can use idle timer library https://www.npmjs.com/package/react-idle-timer


constructor()
{
  this.onIdle = this._onIdle.bind(this);
}

_onIdle(e) {
window.removeEventListener("beforeunload", eventfunction);
history.push("/idleTimeOutPage");
}

    <div>

     <IdleTimer

          ref={ref => { this.idleTimer = ref }}

          element={document}

          onIdle={this.onIdle}

          debounce={250}

timeout={1000 * 60 * GlobalSettings.IDLE_TIMEOUT}

/>


     <ErrBoundary>
        <Router history={history}>
            <Switch>
                 <Route path="/login" component={Login} exact />
                 <PrivateRoute path="/" component={MainPage} exact />     

.....
 <Route path="*" component={PageNotFoundPage} exact />
             </Switch>
         </Router>
     </ErrBoundary>

     </div>