Skip to content

Commit

Permalink
Use route.matched insted of full path to detect route relations
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaynesov committed Jul 4, 2017
1 parent 1d6c358 commit 3396a5a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@ class VueBodyClassController {
router.beforeEach((to, from, next) => {

var parent = router.options.routes;
let pathSplitted = to.path.split('/');
let matched = [];
var additionalClassName = "";
let goDeep;

pathSplitted = pathSplitted.filter(function(n){ return (n) });
goDeep = (to.path != '/' && to.path.length > 0 && pathSplitted.length > 0);
for (let index in to.matched) {

if (goDeep) {
let prev = matched.join('/');

for (var prop in pathSplitted) {
matched.push(to.matched[index].path
.replace(/^\/|\/$/g, '')
.replace(prev, '')
.replace(/^\/|\/$/g, ''));

}

if (to.path != '/' && to.path.length > 0 && matched.length > 0) {

This comment has been minimized.

Copy link
@ktmud

ktmud Sep 4, 2017

Why do we need to.path != '/' here? It makes it impossible to assign a bodyClass for the homepage.


for (let index in matched) {

let data = parent.children ? parent.children : parent;
let found;

found = data.find((o)=> {

return o.path == '/' + pathSplitted[prop] || o.path == pathSplitted[prop];
return o.path.replace(/^\/|\/$/g, '') == matched[index];

});

Expand Down

0 comments on commit 3396a5a

Please sign in to comment.