Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • DSA
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps
    • Software and Tools
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Go Premium
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App

React JS Types of Routers

Last Updated : 12 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

When creating a React application, managing navigation between different views or pages is important. React Router is the standard library for routing in React, enabling seamless navigation while maintaining the Single Page Application (SPA) behaviour.

What is React Router?

React Router is a declarative, component-based routing library for React applications. It enables navigation without reloading the page, making the application faster and more dynamic.

  • Supports client-side routing in React applications.
  • Provides nested routes for better organization.
  • Allows for dynamic routing using parameters.
  • Enables programmatic navigation via hooks like useNavigate().

Before diving into types of routers, let’s ensure that React Router DOM is installed in your React project

npm install react-router-dom

Types of Routers in React

React provides several types of routers that serve different purposes. The main routers in React are

  1. Browser Router (<BrowserRouter>)
  2. Hash Router (<HashRouter>)
  3. Memory Router (<MemoryRouter>)
  4. Static Router (<StaticRouter>)
  5. Native Router (<NativeRouter>)

1. Browser Router

BrowserRouter is the most commonly used router in React applications that are deployed in a modern web environment.

  • It uses the HTML5 history API to manage the navigation.
  • This router makes use of pushState, replaceState, and the popState event to keep the UI in sync with the URL.
  • It allows for clean and human-readable URLs without hash fragments.

When to Use BrowserRouter

BrowserRouter is a powerful and commonly used router in React applications, and it’s ideal for web applications that require clean, SEO-friendly URLs and rely on server-side routing.

  • Hosting on a Web Server with Proper Routing: BrowserRouter works best when your app is hosted on a web server that can handle dynamic URLs (server-side routing).
  • Improved SEO: Since BrowserRouter generates URLs without the hash, search engines can more easily crawl and index your pages.
  • Single Page Applications (SPA): BrowserRouter is commonly used in SPAs, where the entire app runs on a single page.
  • Handling Multiple Views or Pages: If your app includes multiple views or pages BrowserRouter helps manage these views by linking each one to a specific URL.
App.js
import React from "react";
import { BrowserRouter, Routes, Route, Link } from "react-router-dom";
import Home from "./components/Home";
import About from "./components/About";
import Contact from "./components/Contact";

const App = () => {
    return (
        <BrowserRouter>
            <div style={{ fontFamily: "Arial, sans-serif" }}>
                {/* Navigation Bar */}
                <nav
                    style={{
                        backgroundColor: "#333",
                        padding: "10px",
                        display: "flex",
                        justifyContent: "center",
                    }}
                >
                    <ul
                        style={{
                            listStyle: "none",
                            display: "flex",
                            gap: "20px",
                            padding: "0",
                            margin: "0",
                        }}
                    >
                        <li>
                            <Link to="/" style={linkStyle}>
                                Home
                            </Link>
                        </li>
                        <li>
                            <Link to="/about" style={linkStyle}>
                                About Us
                            </Link>
                        </li>
                        <li>
                            <Link to="/contact" style={linkStyle}>
                                Contact Us
                            </Link>
                        </li>
                    </ul>
                </nav>

                {/* Page Content */}
                <div
                    style={{ display: "flex", justifyContent: "center", padding: "20px" }}
                >
                    <Routes>
                        <Route path="/" element={<Home />} />
                        <Route path="/about" element={<About />} />
                        <Route path="/contact" element={<Contact />} />
                    </Routes>
                </div>
            </div>
        </BrowserRouter>
    );
};

// Style for navigation links
const linkStyle = {
    textDecoration: "none",
    color: "white",
    fontSize: "18px",
    fontWeight: "bold",
};

export default App;
Home.js
import React from "react";

const Home = () => {
    return (
        <div style={{ textAlign: "center", maxWidth: "600px" }}>
            <h2 style={{ color: "#2c3e50" }}>Home Page</h2>
            <p style={{ fontSize: "18px", fontWeight: "bold" }}>
                Welcome to the home page!
            </p>
        </div>
    );
};

export default Home;
About.js
import React from "react";

const About = () => {
    return (
        <div style={{ textAlign: "center", maxWidth: "600px" }}>
            <h2 style={{ color: "#2c3e50" }}>About Us</h2>
            <p style={{ fontSize: "18px", fontWeight: "bold" }}>
                GeeksforGeeks is a computer science portal. You can visit it here:
                <a
                    href="https://www.geeksforgeeks.org/"
                    target="_blank"
                    rel="noopener noreferrer"
                    style={{
                        textDecoration: "none",
                        color: "#007bff",
                        fontWeight: "bold",
                    }}
                >
                    GeeksforGeeks
                </a>
            </p>
        </div>
    );
};

export default About;
Conatact.js
import React from "react";

const Contact = () => {
    return (
        <div style={{ textAlign: "center", maxWidth: "600px" }}>
            <h2 style={{ color: "#2c3e50" }}>Contact Us</h2>
            <p style={{ fontSize: "18px", fontWeight: "bold" }}>
                You can find us here:
            </p>
            <address
                style={{
                    fontSize: "16px",
                    fontWeight: "bold",
                    color: "#333",
                    marginTop: "10px",
                }}
            >
                GeeksforGeeks, 5th Floor, A-118, Sector-136, Noida, Uttar Pradesh -
                201305, India
            </address>
        </div>
    );
};

export default Contact;

Output

routing
BrowserRouter

In this code

  • App.js: Uses BrowserRouter for navigation with clean URLs (e.g., /about). It defines routes and a navigation menu.
  • Home.js: Displays a simple home page with a welcome message.
  • About.js: Shows an "About Us" section with a GeeksforGeeks link.
  • Contact.js: Displays contact details with the GeeksforGeeks Noida address.

2. Memory Router

Memory Router is used when there is no web browser, like in testing or mobile apps. It remembers the navigation history inside the app but does not change the URL. This makes it helpful for testing and non-browser environments.

  • No URL Change: Unlike Browser Router or HashRouter, MemoryRouter does not change the browser's URL. It stores the location state internally.
  • In-memory history: It maintains history in memory, not in the URL or browser history, making it ideal for non-browser environments.

When to Use Memory Router

Here are some use cases of Memory Router

  • Server-Side Rendering (SSR): When rendering React components on the server, where there is no URL to manage.
  • Testing: Ideal for unit tests, allowing routing logic to be tested without modifying the browser’s URL.
  • React Native: Since React Native doesn't rely on URLs, Memory Router helps manage navigation in mobile apps.
  • Non-Browser Environments: Useful in applications like Electron where the app does not interact with a browser's URL.
  • When URL Doesn’t Matter: If you don’t need to reflect state changes in the URL, Memory Router can manage routing internally
App.js
import React from "react";
import { MemoryRouter, Routes, Route, Link } from "react-router-dom";
import Home from "./components/Home";
import About from "./components/About";
import Contact from "./components/Contact";

const App = () => {
    return (
        <MemoryRouter>
            <div style={{ fontFamily: "Arial, sans-serif" }}>
                {/* Navigation Bar */}
                <nav
                    style={{
                        backgroundColor: "#333",
                        padding: "10px",
                        display: "flex",
                        justifyContent: "center",
                    }}
                >
                    <ul
                        style={{
                            listStyle: "none",
                            display: "flex",
                            gap: "20px",
                            padding: "0",
                            margin: "0",
                        }}
                    >
                        <li>
                            <Link to="/" style={linkStyle}>
                                Home
                            </Link>
                        </li>
                        <li>
                            <Link to="/about" style={linkStyle}>
                                About Us
                            </Link>
                        </li>
                        <li>
                            <Link to="/contact" style={linkStyle}>
                                Contact Us
                            </Link>
                        </li>
                    </ul>
                </nav>

                {/* Page Content */}
                <div
                    style={{ display: "flex", justifyContent: "center", padding: "20px" }}
                >
                    <Routes>
                        <Route path="/" element={<Home />} />
                        <Route path="/about" element={<About />} />
                        <Route path="/contact" element={<Contact />} />
                    </Routes>
                </div>
            </div>
        </MemoryRouter>
    );
};

// Style for navigation links
const linkStyle = {
    textDecoration: "none",
    color: "white",
    fontSize: "18px",
    fontWeight: "bold",
};

export default App;
Home.js
import React from "react";

const Home = () => {
    return (
        <div style={{ textAlign: "center", maxWidth: "600px" }}>
            <h2 style={{ color: "#2c3e50" }}>Home Page</h2>
            <p style={{ fontSize: "18px", fontWeight: "bold" }}>
                Welcome to the home page!
            </p>
        </div>
    );
};

export default Home;
Contact.js
import React from "react";

const Contact = () => {
    return (
        <div style={{ textAlign: "center", maxWidth: "600px" }}>
            <h2 style={{ color: "#2c3e50" }}>Contact Us</h2>
            <p style={{ fontSize: "18px", fontWeight: "bold" }}>
                You can find us here:
            </p>
            <address
                style={{
                    fontSize: "16px",
                    fontWeight: "bold",
                    color: "#333",
                    marginTop: "10px",
                }}
            >
                GeeksforGeeks, 5th Floor, A-118, Sector-136, Noida, Uttar Pradesh -
                201305, India
            </address>
        </div>
    );
};

export default Contact;
About.js
import React from "react";

const About = () => {
    return (
        <div style={{ textAlign: "center", maxWidth: "600px" }}>
            <h2 style={{ color: "#2c3e50" }}>About Us</h2>
            <p style={{ fontSize: "18px", fontWeight: "bold" }}>
                GeeksforGeeks is a computer science portal. You can visit it here:
                <a
                    href="https://www.geeksforgeeks.org/"
                    target="_blank"
                    rel="noopener noreferrer"
                    style={{
                        textDecoration: "none",
                        color: "#007bff",
                        fontWeight: "bold",
                    }}
                >
                    GeeksforGeeks
                </a>
            </p>
        </div>
    );
};

export default About;

Output

routing
Memory Router

In this code

  • Contact.js: Displays a "Contact Us" section with an address (GeeksforGeeks Noida) in a bold, formatted style.
  • About.js: Shows an "About Us" section with a brief description of GeeksforGeeks and a clickable link to its website.
  • When linked in React Router, they render on /contact and /about routes.

3. Hash Router

A Hash Router is another type of router used in React applications. It works by using the hash portion of the URL (the part that comes after the # symbol) to manage navigation.

  • It uses URL hash (#) to represent different routes (e.g., http://example.com/#/home).
  • The hash part is not sent to the server but is used to change the displayed content in the browser.
  • It's useful for handling navigation in environments where you can't use regular URLs (like in static websites or when there's no server-side routing).

When to Use Hash Router

HashRouter is a useful and simple router for React applications that rely on URL hashes for navigation, especially in environments where server-side routing is not available.

  • Hosting on Static File Servers: HashRouter works best when your app is hosted on static file servers, like GitHub Pages, that cannot handle dynamic routing or need the URL to stay static.
  • No Server-Side Routing: Ideal for situations where server-side routing is not set up or you don’t have access to configure it. It keeps the routing within the client-side, without needing the server to manage different routes.
  • Simpler Projects: For smaller, simpler projects or prototypes that don't require clean URLs or SEO optimization, HashRouter offers an easy solution for adding routing
App.js
import React from "react";
import { HashRouter, Routes, Route, Link } from "react-router-dom";
import Home from "./components/Home";
import About from "./components/About";
import Contact from "./components/Contact";

const App = () => {
    return (
        <HashRouter>
            <div style={{ fontFamily: "Arial, sans-serif" }}>
                {/* Navigation Bar */}
                <nav
                    style={{
                        backgroundColor: "#333",
                        padding: "10px",
                        display: "flex",
                        justifyContent: "center",
                    }}
                >
                    <ul
                        style={{
                            listStyle: "none",
                            display: "flex",
                            gap: "20px",
                            padding: "0",
                            margin: "0",
                        }}
                    >
                        <li>
                            <Link to="/" style={linkStyle}>
                                Home
                            </Link>
                        </li>
                        <li>
                            <Link to="/about" style={linkStyle}>
                                About Us
                            </Link>
                        </li>
                        <li>
                            <Link to="/contact" style={linkStyle}>
                                Contact Us
                            </Link>
                        </li>
                    </ul>
                </nav>

                {/* Page Content */}
                <div
                    style={{ display: "flex", justifyContent: "center", padding: "20px" }}
                >
                    <Routes>
                        <Route path="/" element={<Home />} />
                        <Route path="/about" element={<About />} />
                        <Route path="/contact" element={<Contact />} />
                    </Routes>
                </div>
            </div>
        </HashRouter>
    );
};

// Style for navigation links
const linkStyle = {
    textDecoration: "none",
    color: "white",
    fontSize: "18px",
    fontWeight: "bold",
};

export default App;
Home.js
import React from "react";

const Home = () => {
    return (
        <div style={{ textAlign: "center", maxWidth: "600px" }}>
            <h2 style={{ color: "#2c3e50" }}>Home Page</h2>
            <p style={{ fontSize: "18px", fontWeight: "bold" }}>
                Welcome to the home page!
            </p>
        </div>
    );
};

export default Home;
About.js
import React from "react";

const About = () => {
    return (
        <div style={{ textAlign: "center", maxWidth: "600px" }}>
            <h2 style={{ color: "#2c3e50" }}>About Us</h2>
            <p style={{ fontSize: "18px", fontWeight: "bold" }}>
                GeeksforGeeks is a computer science portal. You can visit it here:
                <a
                    href="https://www.geeksforgeeks.org/"
                    target="_blank"
                    rel="noopener noreferrer"
                    style={{
                        textDecoration: "none",
                        color: "#007bff",
                        fontWeight: "bold",
                    }}
                >
                    GeeksforGeeks
                </a>
            </p>
        </div>
    );
};

export default About;
Contact.js
import React from "react";

const Contact = () => {
    return (
        <div style={{ textAlign: "center", maxWidth: "600px" }}>
            <h2 style={{ color: "#2c3e50" }}>Contact Us</h2>
            <p style={{ fontSize: "18px", fontWeight: "bold" }}>
                You can find us here:
            </p>
            <address
                style={{
                    fontSize: "16px",
                    fontWeight: "bold",
                    color: "#333",
                    marginTop: "10px",
                }}
            >
                GeeksforGeeks, 5th Floor, A-118, Sector-136, Noida, Uttar Pradesh -
                201305, India
            </address>
        </div>
    );
};

export default Contact;

output

routing
Hash Router

In this code

  • App.js: Uses HashRouter for navigation. It contains a navigation bar with links and defines routes for Home, About, and Contact pages.
  • Home.js: Displays a simple Home Page with a heading and a welcome message.
  • About.js: Shows an "About Us" section describing GeeksforGeeks with a clickable link.
  • Contact.js: Displays a "Contact Us" section with the GeeksforGeeks Noida address.

Conclusion

Routing is a fundamental concept in React that allows you to create interactive and dynamic applications. Understanding the different types of routers, like BrowserRouter and HashRouter, will help you choose the right approach based on your project’s requirements. Each router has its use case, and picking the one that suits your application’s needs will ensure a smooth and error-free experience.


React JS Types of Routers

V

verma_anushka
Improve
Article Tags :
  • Technical Scripter
  • Web Technologies
  • ReactJS
  • ReactJS-Router

Similar Reads

    React Tutorial
    React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
    7 min read

    React Fundamentals

    React Introduction
    ReactJS is a component-based JavaScript library used to build dynamic and interactive user interfaces. It simplifies the creation of single-page applications (SPAs) with a focus on performance and maintainability. "Hello, World!" Program in ReactJavaScriptimport React from 'react'; function App() {
    6 min read
    React Environment Setup
    To run any React application, we need to first setup a ReactJS Development Environment. In this article, we will show you a step-by-step guide to installing and configuring a working React development environment.Pre-requisite:We must have Nodejs installed on our PC. So, the very first step will be
    3 min read
    React JS ReactDOM
    ReactDOM is a core React package that provides DOM-specific methods to interact with and manipulate the Document Object Model (DOM), enabling efficient rendering and management of web page elements. ReactDOM is used for: Rendering Components: Displays React components in the DOM.DOM Manipulation: Al
    2 min read
    React JSX
    JSX stands for JavaScript XML, and it is a special syntax used in React to simplify building user interfaces. JSX allows you to write HTML-like code directly inside JavaScript, enabling you to create UI components more efficiently. Although JSX looks like regular HTML, it’s actually a syntax extensi
    5 min read
    ReactJS Rendering Elements
    In this article we will learn about rendering elements in ReactJS, updating the rendered elements and will also discuss about how efficiently the elements are rendered.What are React Elements?React elements are the smallest building blocks of a React application. They are different from DOM elements
    3 min read
    React Lists
    In lists, React makes it easier to render multiple elements dynamically from arrays or objects, ensuring efficient and reusable code. Since nearly 85% of React projects involve displaying data collections—like user profiles, product catalogs, or tasks—understanding how to work with lists.To render a
    4 min read
    React Forms
    In React, forms are used to take input from users, like text, numbers, or selections. They work just like HTML forms but are often controlled by React state so you can easily track and update the input values.Example:JavaScriptimport React, { useState } from 'react'; function MyForm() { const [name,
    4 min read
    ReactJS Keys
    A key serves as a unique identifier in React, helping to track which items in a list have changed, been updated, or removed. It is particularly useful when dynamically creating components or when users modify the list. When rendering a list, you need to assign a unique key prop to each element in th
    4 min read

    Components in React

    React Components
    In React, components are reusable, independent code blocks (A function or a class) that define the structure and behavior of the UI. They accept inputs (props or properties) and return elements that describe what should appear on the screen.Key Concepts of React Components:Each component handles its
    4 min read
    ReactJS Functional Components
    In ReactJS, functional components are a core part of building user interfaces. They are simple, lightweight, and powerful tools for rendering UI and handling logic. Functional components can accept props as input and return JSX that describes what the component should render.Example:JavaScriptimport
    4 min read
    React Class Components
    Class components are ES6 classes that extend React.Component. They allow state management and lifecycle methods for complex UI logic.Used for stateful components before Hooks.Support lifecycle methods for mounting, updating, and unmounting.The render() method in React class components returns JSX el
    3 min read
    ReactJS Pure Components
    ReactJS Pure Components are similar to regular class components but with a key optimization. They skip re-renders when the props and state remain the same. While class components are still supported in React, it's generally recommended to use functional components with hooks in new code for better p
    4 min read
    ReactJS Container and Presentational Pattern in Components
    In this article we will categorise the react components in two types depending on the pattern in which they are written in application and will learn briefly about these two categories. We will also discuss about alternatives to this pattern. Presentational and Container ComponentsThe type of compon
    2 min read
    ReactJS PropTypes
    In ReactJS PropTypes are the property that is mainly shared between the parent components to the child components. It is used to solve the type validation problem.Type Safety: When the wrong data type is passed in the component, prototypes help find the issues.Better Debugging: During development, t
    5 min read
    React Lifecycle
    In React, the lifecycle refers to the various stages a component goes through. These stages allow developers to run specific code at key moments, such as when the component is created, updated, or removed. By understanding the React lifecycle, you can better manage resources, side effects, and perfo
    7 min read

    React Hooks

    React Hooks
    ReactJS Hooks, introduced in React 16.8, are among the most impactful updates to the library, with over 80% of modern React projects adopting them for state and lifecycle management. They let developers use state, side effects, and other React features without writing class components. Hooks streaml
    8 min read
    React useState Hook
    The useState hook is a function that allows you to add state to a functional component. It is an alternative to the useReducer hook that is preferred when we require the basic update. useState Hooks are used to add the state variables in the components. For using the useState hook we have to import
    5 min read
    ReactJS useEffect Hook
    The useEffect hook is one of the most commonly used hooks in ReactJS, used to handle side effects in functional components. Before hooks, these kinds of tasks were only possible in class components through lifecycle methods like componentDidMount, componentDidUpdate, and componentWillUnmount.Fetchin
    5 min read

    Routing in React

    React Router
    React Router is a JavaScript library designed specifically for React to handle client-side routing. It maps specific URL paths to React components, allowing users to navigate between different pages or sections without refreshing the entire page.Types of React RoutersThere are three types of routers
    5 min read
    React JS Types of Routers
    When creating a React application, managing navigation between different views or pages is important. React Router is the standard library for routing in React, enabling seamless navigation while maintaining the Single Page Application (SPA) behaviour.What is React Router?React Router is a declarati
    10 min read

    Advanced React Concepts

    Lazy Loading in React and How to Implement it ?
    Lazy Loading in React is used to initially load and render limited data on the webpage. It helps to optimize the performance of React applications. The data is only rendered when visited or scrolled it can be images, scripts, etc. Lazy loading helps to load the web page quickly and presents the limi
    4 min read
    ReactJS Higher-Order Components
    Higher-order components (HOC) are an advanced technique in React that is used for reusing component logic. It is the function that takes the original component and returns the new enhanced component.It doesn’t modify the input component directly. Instead, they return a new component with enhanced be
    5 min read
    Code Splitting in React
    Code-Splitting is a feature supported by bundlers like Webpack, Rollup, and Browserify which can create multiple bundles that can be dynamically loaded at runtime.As websites grow larger and go deeper into components, it becomes heavier. This is especially the case when libraries from third parties
    4 min read

    React Projects

    Create ToDo App using ReactJS
    This to-do list allows users to add new tasks and delete them by clicking the corresponding button. The logic is handled by a click event handler whenever the user clicks on a task it gets deleted from the list.Lets have a quick look at what the final application will look like:ToDo App using ReactJ
    3 min read
    Create a Quiz App using ReactJS
    In this article, we will create a quiz application to learn the basics of ReactJS. We will be using class components to create the application with custom and bootstrap styling. The application will start with questions at first and then the score will be displayed at last. Initially, there are only
    4 min read
    Create a Coin Flipping App using ReactJS
    In this article, we will build a coin flipping application. In which the user can flip a coin and get a random result from head or tails. We create three components 'App' and 'FlipCoin' and 'Coin'. The app component renders a single FlipCoin component only. FlipCoin component contains all the behind
    3 min read
    How to create a Color-Box App using ReactJS?
    Basically we want to build an app that shows the number of boxes which has different colors assigned to each of them. Each time the app loads different random colors are assigned. when a user clicks any of the boxes, it changes its color to some different random color that does not equal to its prev
    4 min read
    Dice Rolling App using ReactJS
    This article will create a dice-rolling application that rolls two dice and displays a random number between 1 and 6 as we click the button both dice shake and generate a new number that shows on the upper face of the dice (in dotted form as a standard dice). The numbers on the upper face are genera
    4 min read
    Guess the number with React
    In this article, we will create the guess the number game. In which the computer will select a random number between 1 and 20 and the player will get unlimited chances to guess the number. If the player makes an incorrect guess, the player will be notified whether the guess is is higher or lower tha
    3 min read
`; $(commentSectionTemplate).insertBefore(".article--recommended"); } loadComments(); }); }); function loadComments() { if ($("iframe[id*='discuss-iframe']").length top_of_element && top_of_screen articleRecommendedTop && top_of_screen articleRecommendedBottom)) { if (!isfollowingApiCall) { isfollowingApiCall = true; setTimeout(function(){ if (loginData && loginData.isLoggedIn) { if (loginData.userName !== $('#followAuthor').val()) { is_following(); } else { $('.profileCard-profile-picture').css('background-color', '#E7E7E7'); } } else { $('.follow-btn').removeClass('hideIt'); } }, 3000); } } }); } $(".accordion-header").click(function() { var arrowIcon = $(this).find('.bottom-arrow-icon'); arrowIcon.toggleClass('rotate180'); }); }); window.isReportArticle = false; function report_article(){ if (!loginData || !loginData.isLoggedIn) { const loginModalButton = $('.login-modal-btn') if (loginModalButton.length) { loginModalButton.click(); } return; } if(!window.isReportArticle){ //to add loader $('.report-loader').addClass('spinner'); jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', { PRACTICE_API_URL: practiceAPIURL, PRACTICE_URL:practiceURL },function(responseTxt, statusTxt, xhr){ if(statusTxt == "error"){ alert("Error: " + xhr.status + ": " + xhr.statusText); } }); }else{ window.scrollTo({ top: 0, behavior: 'smooth' }); $("#report_modal_content").show(); } } function closeShareModal() { const shareOption = document.querySelector('[data-gfg-action="share-article"]'); shareOption.classList.remove("hover_share_menu"); let shareModal = document.querySelector(".hover__share-modal-container"); shareModal && shareModal.remove(); } function openShareModal() { closeShareModal(); // Remove existing modal if any let shareModal = document.querySelector(".three_dot_dropdown_share"); shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" })); document.querySelector(".hover__share-modal-container").append( Object.assign(document.createElement('div'), { className: "share__modal" }), ); document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" })); const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"]; socialOptions.forEach((socialOption) => { const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" }); const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` }); const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` }); const shareLink = (socialOption === "Copy Link") ? Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) : Object.assign(document.createElement('a'), { className: "link-container" }); if (socialOption === "LinkedIn") { shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`); shareLink.setAttribute('target', '_blank'); } if (socialOption === "WhatsApp") { shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } if (socialOption === "Twitter") { shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } shareLink.append(icon, socialText); socialContainer.append(shareLink); document.querySelector(".share__modal").appendChild(socialContainer); //adding copy url functionality if(socialOption === "Copy Link") { shareLink.addEventListener("click", function() { var tempInput = document.createElement("input"); tempInput.value = window.location.href; document.body.appendChild(tempInput); tempInput.select(); tempInput.setSelectionRange(0, 99999); // For mobile devices document.execCommand('copy'); document.body.removeChild(tempInput); this.querySelector(".share__option-text").textContent = "Copied" }) } }); // document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu")); } function toggleLikeElementVisibility(selector, show) { document.querySelector(`.${selector}`).style.display = show ? "block" : "none"; } function closeKebabMenu(){ document.getElementById("myDropdown").classList.toggle("show"); }
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Campus Training Program
  • Explore
  • POTD
  • Job-A-Thon
  • Community
  • Videos
  • Blogs
  • Nation Skill Up
  • Tutorials
  • Programming Languages
  • DSA
  • Web Technology
  • AI, ML & Data Science
  • DevOps
  • CS Core Subjects
  • Interview Preparation
  • GATE
  • Software and Tools
  • Courses
  • IBM Certification
  • DSA and Placements
  • Web Development
  • Programming Languages
  • DevOps & Cloud
  • GATE
  • Trending Technologies
  • Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
  • Preparation Corner
  • Aptitude
  • Puzzles
  • GfG 160
  • DSA 360
  • System Design
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences