ui-router-server / location / serverLocationPlugin
Function: serverLocationPlugin()
function serverLocationPlugin(uiRouter, options?): LocationPlugin;Defined in: location.ts:83
The memory location plugin a server render installs, in the url shape its client uses.
The router's own memoryLocationPlugin is hash-shaped and cannot be asked for anything else — its html5Mode() is false — so stateService.href('sheet', { num: '7B' }) comes back as #/sheet/7B on the server while a pushState browser writes /sheet/7B, and every server-rendered link differs from its hydrated self. This plugin pairs the same in-memory MemoryLocationService with `ServerLocationConfig`, which takes the mode from `html5Mode`: paths by default, to match pushStateLocationPlugin or the Navigation API plugin, and fragments under { html5Mode: false }, to match hashLocationPlugin.
Parameters
| Parameter | Type | Description |
|---|---|---|
uiRouter | UIRouter | the router the plugin is installed on |
options? | ServerLocationPluginOptions | the url shape the client uses |
Returns
LocationPlugin
the installed location plugin
Example
import { UIRouter } from '@uirouter/core';
import { serverLocationPlugin } from 'ui-router-server/location';
const router = new UIRouter();
router.plugin(serverLocationPlugin);
// or, for a hash client:
router.plugin(serverLocationPlugin, { html5Mode: false });