npm gatsby 0.12.31
New browser lifecycle API: `modifyRoutes`

latest releases: 5.14.0-alpha-gatsby.9, 5.14.0-alpha-gatsby.6, 5.13.4...
7 years ago

@scottyeck and @stevensurgnier have been working on a way to add client-side redirects and remove trailing slashes from routes and towards that aim added a new browser lifecycle API modifyRoutes in #657

Some examples they came up with.

Add redirects:

exports.modifyRoutes = routes => {
    const redirects = [
        {
            path: '/cat',
            onEnter: (nextState, replace) => replace('/dog?utm_campaign=cat')
        }
    ];
    const childRoutesLength = routes.childRoutes.length;
    const childRoutesButLast = routes.childRoutes.slice(0, childRoutesLength - 1);
    const childRoutesLast = routes.childRoutes[childRoutesLength - 1];
    routes.childRoutes = childRoutesButLast.concat(redirects).concat([childRoutesLast]);
    return routes;
};

Remove trailing slashes:

exports.modifyRoutes = routes => {
    routes.childRoutes.forEach(route => route.path = route.path.replace(/\/$/, ''));
    return routes;
};

Don't miss a new gatsby release

NewReleases is sending notifications on new releases.