Git Product home page Git Product logo

next-i18n-routes-middleware's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar hamandrock avatar landsman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

next-i18n-routes-middleware's Issues

navigation example

move here our navigation component and think how simplifie it - no dependency to lingui

add helper functions for language switcher

can be in langUtils


function findVariablesInRoute(route)
{
    let items = route.split('/');
    let dynamic = [];

    items.forEach(item => {
        if(item.includes(":")) {
            dynamic.push(item.replace(':', ''));
        }
    });

    return dynamic;
}

function stripTrailingSlash(str) {
    if(str.substr(-1) === '/') {
        return str.substr(0, str.length - 1);
    }
    return str;
}

function composeAddress(lang, route, query)
{
    const dynamic = findVariablesInRoute(route);
    let parsed = new URLSearchParams(query);
    let url = `/${lang}/`;

    dynamic.forEach(part => {
        if(parsed.has(part)) {
            url+=parsed.get(part);
            url+='/';
        }
    });

    url = stripTrailingSlash(url);

    return url;
}

processing dynamic order - logic bug

There is missing some kind of logic which will check all aliases in array and would prefer static one instead of dynamics pages.


URL: http://localhost:3000/cs/autorizace

This order will cause 404 on template: /[code].
Routes:

const paths = {
    homepage: "/route:homepage",
    typeAmount: "/route:venue",
    auth: "/route:auth",
};

// Used at server
const routes = [
    {
        id: paths.homepage,
        template: "/",
        aliases: {
            cs: "/cs",
            en: "/en"
        }
    },
    {
        id: paths.typeAmount,
        template: "/[code]",
        aliases: {
            "cs": "/cs/:code",
            "en": "/en/:code"
        }
    },
    {
        id: paths.auth,
        template: "/auth",
        aliases: {
            "cs": "/cs/autorizace",
            "en": "/en/authentication",
        }
    }
];

module.exports.paths = paths;
module.exports.routes = routes;

This will be processed just fine, without 404.
Routes:

const paths = {
    homepage: "/route:homepage",
    typeAmount: "/route:venue",
    auth: "/route:auth",
};

// Used at server
const routes = [
    {
        id: paths.homepage,
        template: "/",
        aliases: {
            cs: "/cs",
            en: "/en"
        }
    },
    {
        id: paths.auth,
        template: "/auth",
        aliases: {
            "cs": "/cs/autorizace",
            "en": "/en/authentication",
        }
    },
    {
        id: paths.typeAmount,
        template: "/[code]",
        aliases: {
            "cs": "/cs/:code",
            "en": "/en/:code"
        }
    }
];

module.exports.paths = paths;
module.exports.routes = routes;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.