Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ilyasemenov/vue-router-navigation

vue-router helper for generating navigation links
https://github.com/ilyasemenov/vue-router-navigation

vue-router

Last synced: 11 days ago
JSON representation

vue-router helper for generating navigation links

Awesome Lists containing this project

README

        

# vue-router-navigation

`vue-router` helper for generating navigation links when using deeply nested paths.

## Install

```sh
npm install vue-router-navigation
```

## Use

Given a set of nested `vue-router` pages, such as:

- `/orders/123` — main order page
- `/orders/123/details/address` — order address details
- `/orders/123/details/billing` — order billing details
- `/orders/123/tracking` — order tracking

Generate navigation links for Order, Details and Tracking in `pages/orders/[order_id].vue`:

```vue

import { useRouteNavigation } from "vue-router-navigation"

const { prefix } = useRouteNavigation()



Order


Details


Tracking


```

Generate navigation links for Address and Billing in `pages/orders/[order_id]/details.vue`:

```vue

import { useRouteNavigation } from "vue-router-navigation"

const { prefix } = useRouteNavigation()



Address


Billing


```

### Active page

Sometimes vue-router auto-injected CSS classes are not enough. You can explicitly check the active page with:

```vue

import { useRouteNavigation } from "vue-router-navigation"

const { prefix, page } = useRouteNavigation()




  • Order




  • Details




  • Tracking



```

## Nuxt

For Nuxt, create `composables/router-navigation.ts`:

```ts
import { useRoute } from "nuxt/app"
import { useRouteNavigation as useRouteNavigationBase } from "vue-router-navigation"

export const useRouteNavigation = () => useRouteNavigationBase(useRoute())
```

TODO: implement this as a Nuxt module.