Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Regarde si deux route correspondent entre elles
- * @param {[type]} routePathConfig
- * @param {[type]} routePath [description]
- * @return {Boolean} [description]
- */
- export function isMatchingRoute(routePathConfig, routePath) {
- routePathConfig = routePathToArray(routePathConfig);
- routePath = routePathToArray(routePath);
- let matching = routePathConfig.length === routePath.length;
- routePathConfig.map((routePart, index) => {
- if (matching) {
- if (routePart.startsWith(':') && routePath[index]) matching = true;
- else if (routePath[index] === routePart) matching = true;
- else matching = false;
- }
- });
- return matching;
- }
- /**
- * Split un path sur les / pour travailler plus simplement avec
- * @param {[type]} routePath [description]
- * @return {[type]} [description]
- */
- function routePathToArray(routePath) {
- return routePath.split('/').filter(routePart => routePart !== '' && !routePart.startsWith('?'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement