@financial-times/dotcom-middleware-navigation
TypeScript icon, indicating that this package has built-in type declarations

9.3.4 • Public • Published

@financial-times/dotcom-middleware-navigation

This package provides an Express compatible middleware which integrates the FT Navigation package into your application and adds the navigation data, including editions data, to each response making it available to your application's route handlers. This data is required to render the navigation components header and footer.

Getting started

This package is compatible with Node 12+ and is distributed on npm.

npm install --save @financial-times/dotcom-middleware-navigation

After installing the package create a new instance of the middleware and register it with your application. The middleware can be configured with several options:

const express = require('express')
const app = express()

+ const navigation = require('@financial-times/dotcom-middleware-navigation')
+ app.use(navigation.init())

Once registered, a navigation property will be added to the response locals object containing the navigation data.

app.get('/', (request, response) => {
  console.log(response.locals.navigation) // { ... }
})

Options

The middleware accepts the following parameters. All options will be passed along to the FT Navigation package:

enableSubNavigation

Enables fetching hierarchical navigation data for the current path including any parent and child pages. Defaults to false.

getCurrentPath

Enables overriding of the default current path logic. Defaults to:

  (request) => normalizePath(request.get('ft-vanity-url') || request.path)

interval

See the FT navigation documentation for more details.

subNavigationUrl

See the FT navigation documentation for more details.

menuUrl

See the FT navigation documentation for more details.

Readme

Keywords

none

Package Sidebar

Install

npm i @financial-times/dotcom-middleware-navigation

Weekly Downloads

174

Version

9.3.4

License

MIT

Unpacked Size

180 kB

Total Files

17

Last publish

Collaborators

  • robertboulton
  • seraph2000
  • hamza.samih
  • notlee
  • emmalewis
  • aendra
  • the-ft
  • rowanmanning
  • chee
  • alexwilson