Spruha -Routing

Routing

In a single-page application, you change what the user sees by showing or hiding portions of the display that correspond to particular components, rather than going out to the server to get a new page. As users perform application tasks, they need to move between the different views that you have defined.

To handle the navigation from one view to the next, you use the React Router. The Router enables navigation by interpreting a browser URL as an instruction to change the view. Your complete route structure is place at index.js file under src » index.js

Suppose you want to create a new module ( For creating a new module refer create new module ) then you have to add new routes for that modules.


Basic Route

Following are the fundamental building blocks to creating a route.

  1. Import the index.js into App.js and add it to the imports array.
  2. 
    import React, { Fragment } from "react";
    import ReactDOM from "react-dom/client";
    import { BrowserRouter, Route, Routes } from "react-router-dom";
    				
    //component import
    				
    const Dashboard = React.lazy(() => import("./components/Dashboard/Dashboard"))
    const App = React.lazy(() => import("./components/app"));
    				
    <Fragment>
    	<BrowserRouter>
    		<React.Suspense fallback={Loader()}>
    			<Routes>
    				<Route path={`${process.env.PUBLIC_URL}/`}
    				  element={}>
    				  <Route index element={<Dashboard />} />
    				  <Route>
    				    <Route
    				      path={`${process.env.PUBLIC_URL}/Dashboard`}
    				      element={<Dashboard />}
    				    />
    				  </Route>
    				  {/* crytocurrency */}
    				  <Route>
    				    <Route
    				      path={`${process.env.PUBLIC_URL}/crytocurrencies/buysell`}
    				      element={<Buysell />}
    				    />
    				    <Route
    				      path={`${process.env.PUBLIC_URL}/crytocurrencies/dashboard`}
    				      element={<LazyCryptoDashboard />}
    				    />
    				    <Route
    				      path={`${process.env.PUBLIC_URL}/crytocurrencies/market`}
    				      element={<MarketCap />}
    				    />
    				    <Route
    				      path={`${process.env.PUBLIC_URL}/crytocurrencies/currencyechange`}
    				      element={<LazyCurrencyExchange />}
    				    />
    				    <Route
    				      path={`${process.env.PUBLIC_URL}/crytocurrencies/transcations`}
    				      element={<Transcations />}
    				    />
    				    <Route
    				      path={`${process.env.PUBLIC_URL}/crytocurrencies/wallet`}
    				      element={<Wallet />}
    				    />
    				  </Route>
    				</Routes>
    			</React.Suspense>
    		</BrowserRouter>
    </Fragment>
    
    Configure Link in Menu

    To Add new link in Sidemenu

    Following are the fundamental building blocks to creating a new link.

            
    ├── src
    	├──layouts
    		├──Sidebar
    			├──SideMenu.js
    export const MENUITEMS = [
    {
    		menutitle: 'DASHBOARD',
    		Items: [
    			{
    				path: `${process.env.PUBLIC_URL}/dashboard`,
    				icon: 'ti-home',
    				type: 'link',
    				active: false,
    				selected: false,
    				title: 'Dashboard'
    			},
    			{
    				title: 'CryptoCurrencies',
    				icon: 'ti-wallet',
    				type: 'sub',
    				active: false,
    				selected: false,
    				children: [
    					{
    						path: `${process.env.PUBLIC_URL}/crytocurrencies/dashboard`,
    						type: 'link',
    						active: false,
    						selected: false,
    						title: 'Dashboard'
    					},
    					{
    						path: `${process.env.PUBLIC_URL}/crytocurrencies/market`,
    						type: 'link',
    						active: false,
    						selected: false,
    						title: 'Marketcap'
    					},
    					{
    						path: `${process.env.PUBLIC_URL}/crytocurrencies/currencyechange`,
    						type: 'link',
    						active: false,
    						selected: false,
    						title: 'Currency exchange'
    					},
    					
    				]
    			},
    			
    		]
    	}
    ]