npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@travi/hapi-react-router

v6.2.4

Published

hapi route to delegate routing for html content to react-router

Downloads

34

Readme

hapi-react-router

hapi route to delegate routing for html content to react-router v3

Build Status Codecov Node CI Workflow Status

Table of Contents

Usage

npm node license Try @travi/hapi-react-router on RunKit

Installation

$ npm install @travi/hapi-react-router -S

:warning: this plugin expects external babel-helpers to be provided by the consumer

Register with your Hapi v18+ server

Include this plugin in the manifest of your hapi application to direct all requests to /html to a server-side renderer for your react-router routes. It is assumed that something (not included) is in place to direct all text/html requests to this /html route.

In addition, redial fetch hooks will be triggered and rendering will wait for all related requests to complete. This enables populating the data store based on the components that are mounted for the current route. See redial arguments for the list of arguments supplied to triggered fetches.

Example

Dependencies:

import React from 'react';
import {IndexRoute, Route} from 'react-router';
import {createStore} from 'redux';
import {Provider} from 'react-redux';

Register with the Hapi server

export default {
  server: {port: process.env.PORT},
  register: {
    plugins: [
      {plugin: '@travi/hapi-html-request-router'},
      {
        plugin: '@travi/hapi-react-router',
        options: {
          respond: (reply, {renderedContent}) => {
            reply.view('layout', {renderedContent});
          },
          routes: (
            <Route path="/" component={Wrap}>
              <IndexRoute component={Index} />
              <Route path="/foo" component={Foo} />
              <Route path="/bar" component={Bar} />
              <Route path="*" component={NotFound} />
            </Route>
          ),
          Root: ({store, children}) => (
            <Provider store={store}>
              {children}
            </Provider>
          ),
          configureStore: ({session}) => createStore(reducer, composeMiddlewares(session)),
Optional custom renderer that passes blankie (optional to provide yourself) nonces as a prop
          render: (defaultRender, request) => ({html: defaultRender({nonces: request.plugins.blankie.nonces})})
        }
      }
    ]
  }
};

Dependencies for you to provide

This plugin provides you the ability to customize a few steps of the process. Default implementations are currently not provided, so these dependencies are required.

  • respond: a function that will that allows you to call reply on your own, allowing you to perform additional steps before the response
  • routes: the definition of your react-router routes that this plugin should match the request url against
    • If you use a catch-all route to display an appropriate message when the route does not match, it should have a displayName of NotFound. This will enable the status code to be passed to respond as 404. Please note that the automatic mapping of the name property should not be relied on because it can be mangled during minification and, therefore, not match in production.
  • Root: a react component that will wrap the mounted components that result from the matched route
  • store: a data store that will be passed as a prop to the <Root /> component so that your component can inject it into the context through a provider component.
  • render: optional custom renderer to replace the default renderer. Passed defaultRenderer and request as arguments so additional props can be passed to the defaultRenderer, potentially from the request.

Redial fetch trigger arguments

  • params: pass-through of react-router params taken from the path
  • dispatch: redux store dispatch method
  • state: current state of the redux store
  • getState: method to get the latest state of the redux store
  • store: the raw redux store. :warning: WARNING: this should only be used for unique circumstances (e.g., creating a custom subscription to the store)

Contribution

Commitizen friendly semantic-release Renovate

Install dependencies

$ nvm install
$ npm install

Verification

$ npm test

Run the example app

$ npm start