Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. /**
  2. * Regarde si deux route correspondent entre elles
  3. * @param {[type]} routePathConfig
  4. * @param {[type]} routePath [description]
  5. * @return {Boolean} [description]
  6. */
  7. export function isMatchingRoute(routePathConfig, routePath) {
  8. routePathConfig = routePathToArray(routePathConfig);
  9. routePath = routePathToArray(routePath);
  10.  
  11. let matching = routePathConfig.length === routePath.length;
  12. routePathConfig.map((routePart, index) => {
  13. if (matching) {
  14. if (routePart.startsWith(':') && routePath[index]) matching = true;
  15. else if (routePath[index] === routePart) matching = true;
  16. else matching = false;
  17. }
  18. });
  19. return matching;
  20. }
  21.  
  22. /**
  23. * Split un path sur les / pour travailler plus simplement avec
  24. * @param {[type]} routePath [description]
  25. * @return {[type]} [description]
  26. */
  27. function routePathToArray(routePath) {
  28. return routePath.split('/').filter(routePart => routePart !== '' && !routePart.startsWith('?'));
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement