DEV Community

Himanshu Gupta
Himanshu Gupta

Posted on

basename prop in Reactjs

The basename prop is used to provide a base URL path for all the locations in the application. For example, if you want to render your application at the /admin path instead of rendering at the root path /, then specify the basename prop in :


The basename prop now adds the base URL path /admin to the application. When you navigate using and , the basename path is added to the URL. For example, consider the following code with two components:

<BrowserRouter basename="/admin">   
 <div className="component">      
  <nav>         
      <Link to="/">Home</Link>  
      <Link to="/dashboard">Dashboard</Link>  
  </nav>   
 </div>
</BrowserRouter>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)