Modern SharePoint architecture gives fantastic OOTB global navigation, and hub site navigation has amazing potential to maintain consistency throughout the portal. Then why do we need to develop custom global navigation in modern SharePoint sites?

Let us talk about the business scenario.SharePoint-2013-Hosting

Nowadays, a number of organizations are migrating classic intranet portals to modern sites. Many of them have implemented custom global navigation in a classic environment with a number of links and complex tree structures.

Employees are habitual with this global navigation. So, many organizations prefer similar global navigation in Modern SharePoint sites.

Steps

  1. Configure Terms in Term Stores
  2. Create Solution for Application Customizer
  3. Import Required Packages
  4. Create React Component
  5. Add React Component Reference to Application Customizer
  6. Get Terms using PnP
  7. Render Terms using Command Bar and styling
  8. Test Solution

Step 1 – Configure Terms in Term Store.

Go to URL : https://<TenantName>-admin.sharepoint.com/_layouts/15/online/AdminHome.aspx#/termStoreAdminCenter

Create Term Group.

  • Copy Group GUID and Paste it into one document

Create Term Set inside created Term Group

  • Enable Use Term set for Site Navigation
  • Copy term Set Id and Paste it in one document.

Create Terms Inside create Term Sets.

 

Step 2 – Create SPFx Solution for Application Customizer

Open Node command Prompt.

Go to your physical location where you want to create a solution.

Once all required packages are installed then you will get the below message.

 

open Code in visual studio code by typing below one line code in node command prompt.

The solution structure looks like the ad below,

Step 3 – Import required packages from npm

Install PnP npm package,

Install React Fluent UI Package,

Install react and react Dom and Its Dev Dependencies.

Open package.json file which should look like as below,

package.json

Step 4 – Create React Component

Create new folder called “Components” to “..src\extensions\gobalNavigationBar”.

Create 3 files inside the components folder.

  1. GlobalNav.tsx
  2. IGlobalNavProps.ts
  3. IGlobalNavState.ts

 

Add below code to IGlobalNavProps.ts

,

Add below code to IGlobalNavState.ts,

Add below code to IGlobalNav.tsx,

Step 5 – Add React Component Reference to Application Customizer

Open GobalNavigationBarApplicationCustomizer.ts file and add the below code.

GobalNavigationBarApplicationCustomizer.ts

JavaScript

Step 6: Get Terms using PnP

Open GlobalNav.tsx file and do the below changes.

GlobalNav.tsx

Add below references to the file.

Update below code to GlobalNav.tsx.

Update componentdidmount() method with below code in GlobalNav.tsx.

Step 7 – Render Terms using Command Bar

Open GlobalNav.tsx file.

Add below code before default class.

Create new method menuItems() in GlobalNav.tsx file.

Update render() method in GlobalNav.tsx file.

Step 8 – Test Solution

Open “../config/serve.json” file and update a couple of properties.

Update pageUrl Property and Properties,

Run below command in Visual Studio Code Terminal.

Copy URL which is highlighted in yellow and paste it into the browser.

Conclusion

We have implemented the SPFx solution and get terms from the term store using PnP and render items in the command bar which is fluent UI control.