---
title: "Swap a part"
description: "Replace one part of the packaged UI everywhere with an app component of the same name, packaged pages included, or replace a whole page with your own at its path."
canonical_url: "https://nuxt-backend.dev/docs/build/ui/customize/parts"
---
# Swap a part

> Replace one part of the packaged UI everywhere with an app component of the same name, packaged pages included, or replace a whole page with your own at its path.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/parts.ts)

Give every plan card your own design, on `/pricing` and wherever else `<PricingTable>` renders, with one file. Every region of a packaged page or component is a registered part with a name, such as `PricingPlanCard` or `AuthFormCode`. Nuxt already lets an app component shadow a module's component of the same name; the package builds its pages from parts by name, so your component replaces the part everywhere, and receives the same props the packaged one did.

## Swap a part

Create a component in `app/components/` with the part's name. This one replaces each plan card of `<PricingTable>`:

```vue [app/components/PricingPlanCard.vue]
<script setup lang="ts">
import type { PricingPlanCardProps } from '#backend/parts'

const { pricing, plan } = defineProps<PricingPlanCardProps>()
const { t } = useLabels('pricing')
</script>

<template>
  <article v-bind="pricing.bind.planCard(plan)" class="plan">
    <h3>{{ plan.name }}</h3>
    <p class="price">{{ plan.price }}</p>
    <ul>
      <li v-for="feature in plan.features" :key="feature">{{ feature }}</li>
    </ul>
    <button v-bind="pricing.bind.planAction(plan)">{{ t('subscribe') }}</button>
  </article>
</template>
```

A part receives the same props as the packaged one: the parent's headless composable (`pricing`, the `usePricing()` state) and the item it renders (`plan`). The bindings come from that composable, the same attribute and handler bags the packaged part spreads on its own elements. `pricing.bind.planCard(plan)` names the card's group, and `pricing.bind.planAction(plan)` carries the click handler, the `aria-disabled` while a checkout opens and the description that names the plan, so the button stays accessible without a line of ARIA from you. `PricingPlanCardProps` comes from `#backend/parts`, which types every part. The packaged part's stylesheet stops loading once yours takes its name, so your component brings its own styles, and the tokens still reach it.

Run `npx nuxt-backend doctor`: its name-collision finding lists every part you swapped, so a component that shadows one by accident does not go unnoticed.

## Show it in a page

Nothing to change: `/pricing` and every `<PricingTable>` in your pages now render your card. To use your card in one placement only, give it another name and fill the `plan` [slot](https://nuxt-backend.dev/docs/build/ui/customize/slots) there instead.

<table>
<thead>
  <tr>
    <th>
      Some parts
    </th>
    
    <th>
      Part of
    </th>
    
    <th>
      Region
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        AuthFormCode
      </code>
      
      , <code>
        AuthFormPasskey
      </code>
    </td>
    
    <td>
      <code>
        <AuthForm>
      </code>
    </td>
    
    <td>
      The code step, the passkey button
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        PricingPlanCard
      </code>
      
      , <code>
        PricingPeriodSwitch
      </code>
    </td>
    
    <td>
      <code>
        <PricingTable>
      </code>
    </td>
    
    <td>
      A plan card, the monthly and yearly switch
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        AdminUsersTable
      </code>
    </td>
    
    <td>
      <code>
        <AdminUsers>
      </code>
    </td>
    
    <td>
      The accounts table
    </td>
  </tr>
</tbody>
</table>

[Parts](https://nuxt-backend.dev/docs/reference/components/parts) lists every part with its props, slots and the pages that use it.

## Replace a page

Every packaged page mounts, and three ways change one: move it, put a page of yours at its path, or turn it off. The module keeps mounting the pages you did not touch.

### Move a page

The [`pages` module option](https://nuxt-backend.dev/docs/build/ui/pages#move-a-page) gives a page another path:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['nuxt-backend'],
  backend: {
    pages: {
      pricing: '/plans',      // the packaged pricing page, at /plans
      login: '/auth/sign-in', // and the sign-in page; every page guard follows it
    },
  },
})
```

Each path is declared once, there: the auth route, the guards and the invitation emails read it. `pages.<key>: false` turns a page off, for a page you serve somewhere else or a feature you do not offer.

### Put your own page at its path

An app page at a packaged path replaces it: the module detects it, mounts nothing there and logs the override. A path with a parameter counts however its file spells it, so `app/pages/r/[code].vue` replaces the referral page at `/r/:code`. To bring your own profile page, add `app/pages/profile.vue`. It can keep the packaged component and fill a slot, or render something else entirely.

The guard does not come with the path: the module puts it on its own page only. A page of yours in place of a private one declares it:

```vue [app/pages/profile.vue]
<script setup lang="ts">
definePageMeta({ auth: true })
</script>

<template>
  <main>
    <h1>Your profile</h1>
    <ProfileSettings />
  </main>
</template>
```

The private pages ask for a sign-in, and `/admin` for the `admin` role too: a page of yours there declares `definePageMeta({ auth: { role: 'admin' } })` ([Protect pages and routes](https://nuxt-backend.dev/docs/build/auth/access/pages)). Your page also leaves the packaged frame behind, so the `<main>` landmark, the heading and [`<BackendNotices>`](https://nuxt-backend.dev/docs/build/ui/notices) are your layout's. A private path stays out of caches, and out of search indexes while your page has `auth` rules: a page of yours without them is public, and search engines may index it ([Search engines](https://nuxt-backend.dev/docs/build/ui/pages#search-engines)).

### Link to a page wherever it is

`useBackendPagePath(key)` reads a page's path, in the active locale when the app uses `@nuxtjs/i18n`, so a moved page never leaves a stale link:

```vue [app/components/PlansLink.vue]
<script setup lang="ts">
const pricing = useBackendPagePath('pricing')
</script>

<template>
  <NuxtLink :to="pricing">See the plans</NuxtLink>
</template>
```

### Build from composables

A page of your own can drop the packaged component and run on the composables it used, with their bindings ([Build on the composables](https://nuxt-backend.dev/docs/build/ui/customize/headless)):

<table>
<thead>
  <tr>
    <th>
      Page
    </th>
    
    <th>
      Its component runs on
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        /login
      </code>
    </td>
    
    <td>
      <code>
        useLoginFlow
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        /pricing
      </code>
    </td>
    
    <td>
      <code>
        usePricing
      </code>
      
      , <code>
        useBilling
      </code>
      
      , <code>
        useCredits
      </code>
      
      , <code>
        useCampaign
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        /settings
      </code>
    </td>
    
    <td>
      <code>
        useWorkspace
      </code>
      
      , <code>
        useBilling
      </code>
      
      , <code>
        useCredits
      </code>
      
      , <code>
        useFeatures
      </code>
      
      , <code>
        useOrders
      </code>
      
      , <code>
        useUsage
      </code>
      
      , <code>
        useAuditLog
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        /profile
      </code>
    </td>
    
    <td>
      <code>
        useAuth
      </code>
      
      , <code>
        useAccount
      </code>
      
      , <code>
        useEmailChange
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        /security
      </code>
    </td>
    
    <td>
      <code>
        usePasskeys
      </code>
      
      , <code>
        useSessions
      </code>
      
      , <code>
        useReauthentication
      </code>
      
      , <code>
        useAccount
      </code>
      
      , <code>
        useAuditLog
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        /accept-invitation
      </code>
    </td>
    
    <td>
      <code>
        useWorkspace
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        /admin
      </code>
    </td>
    
    <td>
      <code>
        useAdmin
      </code>
      
      , <code>
        useFlagAdmin
      </code>
      
      , <code>
        useAuditLog
      </code>
    </td>
  </tr>
</tbody>
</table>

## What happens when…

<table>
<thead>
  <tr>
    <th>
      Situation
    </th>
    
    <th>
      Result
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Your component has a part's name but not its props
    </td>
    
    <td>
      Nuxt renders it anyway; the type check on <code>
        #backend/parts
      </code>
      
       fails, and <code>
        doctor
      </code>
      
       names the collision
    </td>
  </tr>
  
  <tr>
    <td>
      A part you swapped is removed or renamed in a release
    </td>
    
    <td>
      Your component no longer renders there, and <code>
        doctor
      </code>
      
       stops listing it; the <a href="https://nuxt-backend.dev/docs/ship/releases/upgrade">
        Upgrade page
      </a>
      
       and the rename map name what replaces it
    </td>
  </tr>
  
  <tr>
    <td>
      A page of yours sits at a private path without a guard
    </td>
    
    <td>
      A signed-out visitor sees it: declare <code>
        definePageMeta({ auth: … })
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        pages.login
      </code>
      
       is <code>
        false
      </code>
      
       and you serve no page there
    </td>
    
    <td>
      Guards still redirect to that path: serve your own sign-in page there
    </td>
  </tr>
</tbody>
</table>

## Limits

- **One component per name.** A swapped part replaces it everywhere; for one placement, use a slot.
- **Your part's accessibility is yours.** Spread the `bind` bags, and keep what the region promised ([Accessibility](https://nuxt-backend.dev/docs/build/ui/accessibility#what-a-replacement-must-keep)).
- **Layers and modules.** A Nuxt layer or another module that registers a component with a part's name swaps it too; `doctor` names it.

## Test it

```ts [test/pricing-plan-card.test.ts]
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { createBackendMock, resetBackendMock } from 'nuxt-backend/test-utils'
import { afterEach, expect, it } from 'vitest'
import { PricingTable } from '#components'

afterEach(() => resetBackendMock())

it('renders our plan card on the packaged table', async () => {
  createBackendMock({
    queries: {
      'billing:getPricing': {
        plans: [{ key: 'pro', name: 'Pro', description: null, retired: false, features: [], featureKeys: [], prices: { month: { productId: 'prod_pro', amount: 900, currency: 'eur', monthly: 900 } } }],
        packs: [],
      },
    },
  })
  const table = await mountSuspended(PricingTable)
  expect(table.find('article.plan h3').text()).toBe('Pro')
})
```

[Test pages over a mock backend](https://nuxt-backend.dev/docs/develop/testing/pages) covers `createBackendMock`.

## Related

- [Parts](https://nuxt-backend.dev/docs/reference/components/parts): every part, its props and the pages that use it.
- [Customize with slots](https://nuxt-backend.dev/docs/build/ui/customize/slots): one region of one placement.
- [Build on the composables](https://nuxt-backend.dev/docs/build/ui/customize/headless): your own markup on the bindings.
- [Packaged pages](https://nuxt-backend.dev/docs/build/ui/pages): every page, its key and its route rules.
- [Protect pages and routes](https://nuxt-backend.dev/docs/build/auth/access/pages): the guards a page of yours declares.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
