![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
nuxt-typed-router
Advanced tools
Provide autocompletion for pages route names generated by Nuxt router
Provide a safe typed router to nuxt with auto-generated typed definitions for route names
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.
Problem: If you want a type-safe routing flow, the current model can be hard to maintain if you modify the page file name and is error prone in big projects.
Solution: Thanks to Nuxt powerful hook system, this module reads all your routes and generate typings and enums accordingly
yarn add nuxt-typed-router
#or
npm install nuxt-typed-router
First, register the module in the nuxt.config.[js|ts]
const config = {
...,
modules: [
'nuxt-typed-router',
]
}
Or
const config = {
...,
modules: [
['nuxt-typed-router', {
// options
}],
]
}
Options:
type Options = {
// Path to where you cant the file to be saved (ex: "./src/models/__routes.ts")
filePath?: string;
// Name of the routesNames object (ex: "routesTree")
// Default: "routerPagesNames"
routesObjectName?: string;
// Strip `@` sign from declared routes (ex: `admin/@home.vue` will be accessed like this `routerPagesNames.admin.home`
// and the route name will be `admin-home` instead of `admin-@home`)
// Default: true
stripAtFromNames?: boolean;
};
Nuxt-typed-router provides two ways to have name-based typed routing
Add nuxt-typed-router/types
to your tsconfig.json
types
{
"types": ["@nuxt/types", "nuxt-typed-router/types"],
}
routerPagesNames
global objectThe module will create a file with the global object of the route names inside.
You have to specify the path of the generated file in your configuration
// nuxt.config.js
const config = {
typedRouter: {
filePath: './models/__routes.js', // or .ts,
},
};
// Or
const config = {
modules: [
[
'nuxt-typed-router',
{
filePath: './models/__routes.js', // or .ts,
},
],
],
};
Given this structure
βββ pages
βββ index
βββ content.vue
βββ index.vue
βββ communication.vue
βββ statistics.vue
βββ users.vue
βββ index.vue
βββ forgotpassword.vue
βββ reset-password.vue
β βββ login.vue
βββ ...
The generated file will look like this
export const routerPagesNames = {
forgotpassword: 'forgotpassword',
login: 'login',
resetPassword: 'reset-password',
index: {
index: 'index',
communication: 'index-communication',
content: 'index-content',
statistics: 'index-statistics',
users: 'index-users',
},
};
You can use it from the injected $routeNames
option on your components
export default {
mounted() {
this.$router.push({ name: this.$routeNames.index.content });
},
};
Or you can just import it
import { routerPagesNames } from '~/models/__routes.js';
export default {
mounted() {
this.$router.push({ name: routerPagesNames.index.content });
},
};
The usage is exactly the same as $router
Given this structure
βββ pages
βββ index
βββ content.vue
βββ index.vue
βββ communication.vue
βββ statistics.vue
βββ users.vue
βββ index.vue
βββ forgotpassword.vue
βββ reset-password.vue
β βββ login.vue
βββ ...
This module also provide $typedRoute
, wich is an alias to Vue $route
, but with typed name property
The generated enum is located in the node_modules
folder.
Because of Intellisense limitations, the types from node_modules are not lived updated, so you need to either reload the window or restart Intellisense when you add a Page/ modify the name of a Page for it to take into account the pages names freshly generated
yarn
or npm install
FAQs
Provide autocompletion for routes paths, names and params in Nuxt apps
The npm package nuxt-typed-router receives a total of 11,012 weekly downloads. As such, nuxt-typed-router popularity was classified as popular.
We found that nuxt-typed-router demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenanceβdevelopers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.