Search code examples
meteoriron-router

Iron Router changes router condition


I want to console.log when the router changes only from "home" to "aboutpage" or any other page, but from the homepage.

I am not able to come up with any logic so havent tried anything.


Solution

  • try something like this

    Router.route('/', {
        name : 'home',
        template : 'home',
        title: 'Home'
    });
    
    Router.route('/about', {
        name : 'about',
        template : 'about',
        title: 'About'
    });
    
    Router.onStop(function(){
         Session.set("previousPath",Router.current().route.getName());
    });
    
    Router.onBeforeAction(function(){
        if(Session.get("previousPath")=="home"){
            console.log('something')
        }
        this.next()     
    })