Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

debug react routes

import React, { Component } from 'react';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import Login from 'components/Login'
import DefaultComponent from 'components/DefaultComponent'

class DebugRouter extends BrowserRouter {
  constructor(props){
    super(props);
    console.log('initial history is: ', JSON.stringify(this.history, null,2))
    this.history.listen((location, action)=>{
      console.log(
        `The current URL is ${location.pathname}${location.search}${location.hash}`
      )
      console.log(`The last navigation action was ${action}`, JSON.stringify(this.history, null,2));
    });
  }
}

class App extends Component {
  render() {
    return (
      <DebugRouter>
        <Switch>
          <Route exact path="/login" name="Login Page" component={Login} />
          <Route path="/" name="Home" component={DefaultComponent} />
        </Switch>
      </DebugRouter>
    );
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: return all trs in a table jqueyr 
Javascript :: set localstorage 
Javascript :: mongoose delete 
Javascript :: javascript escape regex 
Javascript :: jsonwebtoken error with react js 
Javascript :: discordjs v13 get message content 
Javascript :: angular print json 
Javascript :: reactjs join two array 
Javascript :: get query params react 
Javascript :: javascript return object property from array 
Javascript :: bin2hex in js 
Javascript :: how to delete an element of an array in javascript 
Javascript :: remove repetition 2d array javascript 
Javascript :: convert array to object 
Javascript :: array iteration 
Javascript :: js object some 
Javascript :: all &nbsp; to space from string javascript 
Javascript :: mongoBD update increment a value by 2 
Javascript :: javascript get black or white text base on color 
Javascript :: regex data 
Javascript :: rotate camera three js 
Javascript :: date javascript format 
Javascript :: link in directive angularjs 
Javascript :: call json api javascript 
Javascript :: javascript href on load delay 
Javascript :: queryselectorall in javascript to get data attribute value 
Javascript :: how to remove particular value in dictionary in nodehs 
Javascript :: react testing for links 
Javascript :: unidirectional data flow 
Javascript :: remove duplicates from array in javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =