@triyanox/next-routes - Never worry about broken links in your Next.js app again!
MIT License
@triyanox/next-routes
- Never worry about broken links in your Next.js app again!@triyanox/next-routes
is a powerful plugin for Next.js that ensures your application's links are always valid. It generates routes and utilities for your application, making link management a breeze.
/about
)/[slug]
)(auth)/login
)/[...slug]
)/[[...slug]]
)Install @triyanox/next-routes
using your favorite package manager:
# pnpm
pnpm add @triyanox/next-routes
# bun
bun add @triyanox/next-routes
# npm
npm i @triyanox/next-routes
# yarn
yarn add @triyanox/next-routes
next.config.js
file, add the following:import withRoutes from '@triyanox/next-routes';
// if you are using the `src` directory you can just
// wrap your config object with `withRoutes`
const config = withRoutes({
//... your next config
});
export default config;
import link$ from '@/lib';
import Link from 'next/link';
const MyComponent = () => {
return (
<Link
href={link$({
path: '/[slug]',
params: {
slug: 'home',
},
hash: 'my-hash',
query: {
foo: 'bar',
},
})}
>
Home
</Link>
);
};
You can customize the behavior of @triyanox/next-routes
by passing an options object to the withRoutes
function. Here's an example:
import withRoutes from '@triyanox/next-routes';
import path from 'path';
import { cwd } from 'process';
// this is an example not using the `src` directory
const config = withRoutes(
{
//... your next config
},
{
appDir: path.resolve(cwd(), './app'),
declarationPath: path.resolve(
cwd(),
'./node_modules/@types/next-routes/index.d.ts',
),
utilsPath: path.resolve(cwd(), './lib/link.ts'),
},
);
export default config;
In this example, the appDir, declarationPath, and utilsPath options are used to customize the behavior of @triyanox/next-routes
.
Contributions are welcome! Please read our contributing guidelines for more information.
This project is licensed under the MIT License - see the LICENSE file for details.