10 examples of 'react router get current route' in JavaScript

Every line of 'react router get current route' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
81currentRoute() {
82 return this._currentRoute;
83}
53getCurrentRoute() {
54 let routeList = _navigator.getCurrentRoutes();
55 let currentRoute = routeList[routeList.length - 1];
56 return currentRoute;
57}
53get currentRoute():Route {
54 return this.routes[this._stack[this._stack.length-1]];
55}
532public static getCurrentRoute():RouterEvent {
533 return this._currentRoute;
534}
622public static getCurrentRoute():RouterEvent
623{
624 return this._currentRoute;
625}
12getCurrentRoute () {
13 const { hash } = window.location
14 return hash ? hash.split('#')[1] : this.defaultRoute
15}
175currentRoute () {
176 const routeData = Matcher.matchPath(this.routes, this.currentPath())
177 if (routeData) {
178 return routeData
179 } else {
180 return null
181 }
182}
27get currentRoute(): any {
28 return this._currentRoute;
29}
38public get currentRoute() {
39 return this._currentRoute;
40}
9export default function Router() {
10 const [current, setCurrent] = useState('home')
11 useEffect(() => {
12 setRoute()
13 window.addEventListener('hashchange', setRoute)
14 return () => window.removeEventListener('hashchange', setRoute)
15 }, [])
16 function setRoute() {
17 const location = window.location.href.split('/')
18 const pathname = location[location.length-1]
19 console.log('pathname: ', pathname)
20 setCurrent(pathname ? pathname : 'home')
21 }
22 return (
23
24 <nav>
25
26
27
28
29
30
31 </nav>
32 )
33}

Related snippets