---
title: setCurrentRouteName (SPA API)
source: https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcurrentroutename
---

## Syntax

```js
newrelic.setCurrentRouteName(string $name)
```

Gives SPA routes more accurate names than default names. Monitors specific routes rather than by default grouping.

## Requirements

-   Browser Pro+SPA agent (v998 or higher)
-   If you're installing the browser agent via npm and building a custom agent with selected features, you must enable the `spa` feature when creating the `Agent` instance. In the `features` array, add the following:

    ```js
    import { Spa } from '@newrelic/browser-agent/features/spa';

    const options = {
      info: { ... },
      loader_config: { ... },
      init: { ... },
      features: [
        Spa
      ]
    }
    ```

    For more information, see the [npm browser installation documentation](https://www.npmjs.com/package/@newrelic/browser-agent#new-relic-browser-agent).

## Description

This method names the current route. This can be useful to:

-   Give routes more accurate names than they would have by default.
-   Monitor a route that might otherwise be grouped with other routes by default.

Currently this method applies only to SPA [`BrowserInteraction`](https://docs.newrelic.com/docs/insights/explore-data/attributes/browser-default-attributes-insights#browserinteraction-attributes) events. Using this API creates two new custom attributes that track the previous route and the target route:

-   `previousRouteName`
-   `targetRouteName`

When using this API, the [`browserInteractionName`](https://docs.newrelic.com/docs/insights/explore-data/attributes/browser-default-attributes-insights#interaction-name) attribute will take the `targetRouteName` value. If `setName` is used to set the browser interaction name, that will take precedence.

The `setCurrentRouteName()` API determines the name attributes for [`BrowserInteraction` events](https://docs.newrelic.com/docs/insights/explore-data/attributes/browser-default-attributes-insights#browserinteraction-attributes), so this API must be called **every time** there is a route change. This will ensure that `BrowserInteraction` events have the correct attributes.

> #### 💡 TIP
>
> Compare with [`setName()`](https://docs.newrelic.com/docs/browser/new-relic-browser/browser-agent-apis/browser-spa-api-newrelicinteractionsetname), which sets a name for a browser interaction, not a route.

## Parameters

| Parameter        | Description                                                                                                                                                                                                                                                                                                                                           |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `$name` _string_ | Required. Current route name for the page. Route names passed to `setCurrentRouteName()` can be any string, but they should represent a routing **pattern** rather than a specific resource. For example, use `/users/:id` rather than `/users/123`. If `null`, exits out of the route change requirement and returns ot the default naming strategy. |

## Examples

```js
router.onChange(function(route) {
  newrelic.setCurrentRouteName(route.name);
});
```
