Skip to content

ui-router-server / vite / serverRouterPlugin

Function: serverRouterPlugin()

ts
function serverRouterPlugin(router, options?): ServerRouterPlugin;

Defined in: vite.ts:47

Wraps a ServerRouter as a Vite plugin. The middleware installs in the PRE position — synchronously inside configureServer, before Vite adds its own middlewares — which is exactly where connect-history-api-fallback sits and the only position that beats Vite's always-200 HTML fallback: a redirect answers 302 and a mount-owned miss answers 404 before Vite can serve index.html. The adapter's shouldHandle still lets module and asset fetches pass untouched, essential under Vite where a mount's module URLs share paths with its routes.

serveShell defaults to rewriting req.url to the mount base and next()ing into Vite's HTML/transform layer (dev) or sirv (preview); point ConnectAdapterOptions.shellPath at the mount's actual HTML entry when it isn't served at the base.

Parameters

ParameterType
routerServerRouter
options?ConnectAdapterOptions

Returns

ServerRouterPlugin