How can I use the page reference for seamless navigation between complex Interactions of multiple pages?

33    Asked by debbieJha in Salesforce , Asked on Apr 10, 2024

 I am currently developing a web-based application that involves multiple pages with complex interactions. How can I execute the page reference to ensure seamless navigation between different sections of the application? 

Answered by debbie Jha

 In the context of Salesforce, you can implement the page reference effectively in a web-based application with multiple pages and complete interactions by using the several techniques which are given below:-

Navigation and routing

You can use a front-end routing library to manage navigation between pages.

URL parameters

You can pass the data between pages by using the URL parameters.

Local storage or session storage

You can store the temporary data or even state information in the local storage of the browser. This would allow you to preserve the preferences of the users.

Cookies

You can use the cookies for storing small pieces of data which is persisting multiple page visits.

Here is a simplified example given

First, let us set up the react application structure:-

Install necessary packages

Npx create-react-app page-reference-app

Cd page-reference-app

Npm install react-router-dom redux react-redux

Create the folder structure

Src

├── components
│ ├── Home.js
│ └── Product.js
├── reducers
│ └── userReducer.js
├── App.js
├── index.js
└── store.js

Add the following code to each file

Src/App.js

Import React from ‘react’;

Import { BrowserRouter as Router, Route, Switch } from ‘react-router-dom’;
Import { Provider } from ‘react-redux’;
Import store from ‘./store’;
Import Home from ‘./components/Home’;
Import Product from ‘./components/Product’;Function App() {
  Return (

   

     

       

         

         

       

     

   

  );

}

Export default App;

Src/Component/Home.js
Import React from ‘react’;
Import { Link } from ‘react-router-dom’;
Function Home() {
  Return (
    
      Welcome to My Web App
      View Product 123
   
  );
}

Export default Home;

Src/Component/product.js
Import React from ‘react’;
Import { useParams } from ‘react-router-dom’;
Import { useSelector } from ‘react-redux’;
Function Product() {
  Const { id } = useParams();
  Const user = useSelector((state) => state.user);

  Return (

   

      Product Details

     

Product ID: {id}


     

User ID from Redux: {user.userId}


   

  );

}

Export default Product;

Src/reducers/userReducer.js
Const initialState = {
  userId: ‘456’, // Initial user ID
};
Const userReducer = (state = initialState, action) => {
  Switch (action.type) {
    Default:
      Return state;
  }
};

Export default userReducer;

Src/store.js
Import { createStore } from ‘redux’;
Import userReducer from ‘./reducers/userReducer’;
Const store = createStore(userReducer);

Export default store;



Your Answer

Interviews

Parent Categories