Add class to specific pages?

  • 0
    how to write url strict before and floating after

    if (document.location.pathname == '/page/....(различные генерируемые страницы где добавляем класс).....')
    JavaScript Anonymous, Jul 24, 2019

  • 1 Answers
  • 0
    Some kind of incoherent question. Well, let's say this:

    const urls = [
    '/page/profile',
    '/page/article/123123',
    '/page/article/new',
    '/page/article',
    '/page/some/nested/structure/here',
    '/page/module/article/new'
    ];

    for (const url of urls ) {
    const expression = /^\/page\/(.*)?(article)(.*)?$/g;

    console.log(url, expression.test(url));
    }
    /*
    '/page/profile' false
    '/page/article/123123' true
    '/page/article/new' true
    '/page/article' true
    '/page/some/nested/structure/here' false
    '/page/module/article/new' true
    */
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!