New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nuxt-typed-router

Package Overview
Dependencies
Maintainers
1
Versions
216
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuxt-typed-router - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

2

lib/module.js

@@ -46,3 +46,3 @@ import fs from 'fs';

});
await fs.writeFileSync(path.resolve(__dirname, options.filePath), formatedModelsFile);
await fs.writeFileSync(path.resolve(process.cwd(), options.filePath), formatedModelsFile);
}

@@ -49,0 +49,0 @@

{
"name": "nuxt-typed-router",
"version": "0.1.1",
"version": "0.1.2",
"description": "Provide autocompletion for pages route names generated by Nuxt router",

@@ -5,0 +5,0 @@ "main": "lib/module.js",

@@ -8,3 +8,3 @@ # 🚦Typed Router Module

## Motivation
# Motivation

@@ -17,3 +17,3 @@ Nuxt is great because it generate the router based on your pages directory. It generates all the pages name and it abstract a lot of boilerplate.

## Installation
# Installation

@@ -27,3 +27,3 @@ ```bash

## Configuration
# Configuration

@@ -54,12 +54,35 @@ First, register the module in the `nuxt.config.[js|ts]`

## Usage
# Usage in Vue/Nuxt
Nuxt-typed-router provides two ways to have name-based typed routing
### - `$typedRouter` (Default)
## - `$typedRouter` (Default)
A global `$typedRouter` method is added to the Nuxt context and is accessible in your components and context. It's an alias of Vue `$router`, but the typings are modified so the `name` options is typed with the routes names generated from the pages directory
_Requirements_
### _Why not directly modifying the types of `$router` and `$route` ?_
That was the idea when I builded this module initially, but I got confronted with Typescript limitations for modifying already defined third-party lib typings.
If I wanted to modify vue-router types, i could have just written this:
```typescript
declare module 'vue-router/types' {
export interface Location {
name: 'login' | 'home';
}
}
```
Unfortunately that's not possible, Typescript throws this errors:
- `Subsequent property declarations must have the same type. Property 'name' must be of type 'string', but here has type '"login" | "home"`
- `All declarations of 'name' must have identical modifiers`
So the only way for now is to have an alternative `$typedRouter`, or a global enum-like object.
### _Requirements_
For your IDE to augment the Vue types, you need to explicitly import the module in your Nuxt config

@@ -72,3 +95,3 @@

_Usage_
### _Usage_

@@ -96,3 +119,3 @@ The usage is exactly the same as `$router`

**_Caveats_**
### **_Caveats_**

@@ -103,7 +126,7 @@ The generated enum is located in the `node_modules` folder.

### - `routerPagesNames` global object
## - `routerPagesNames` global object
The module will create a file with the global object of the route names inside.
**_Requirements_**
### **_Requirements_**

@@ -134,3 +157,3 @@ You have to specify the path of the generated file in your configuration

_Usage_
### _Usage_

@@ -137,0 +160,0 @@ Given this structure

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc