0.1.2 • Published 3 years ago

next-page-rewrites v0.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

Development Version!

next-page-rewrites

Rewrite your next app urls to conventional React naming convention files. E.g. map /user-details to /Pages/UserDetails.js

Not more breaking naming conventions because of Next automatic routing.

Requires a list of pages to be kept up to date.

Usage:

(next.config.js)
const makeRewrites = require('next-page-rewrites);

const pages = [
    'Index',
    'UserDetails',
    'NewsAndEvents',
    'Contact'
];

module.exports = {
    rewrites: makeRewrites(pages)
};
Combine it with your own rewrites function like this
const myRewrites = async () => {
    return [
        {
            source: 'i-like-turtles',
            destination: 'ILikeTurtles'
        }
    ]
}

module.exports = {
    rewrites: makeRewrites(pages, myRewrites)
};

How it works

makeRewrites(pages) will return a function that returns a list of rewrites, in the form of

[
    {
        source: 'index',
        destination: 'Index'
    },
    {
        source: 'user-details',
        destination: 'UserDetails'
    },
    {
        source: 'news-and-events',
        destination: 'NewsAndEvents'
    },
    {
        source: 'contact',
        destination: 'Index'
    },
]

I suggest anagrams be lowercased apart from the first letter for smooth rewrites. E.g. GetHtml not GetHTML.