imba-router icon indicating copy to clipboard operation
imba-router copied to clipboard

Listening to navigation events

Open dragonautdev opened this issue 7 years ago • 0 comments

Hey there! First of all, thanks a lot for imba and this library.

I've just come in contact with it and one thing I've been struggling with is how to detect a route change from a single point.

My approach so far is as follows, but it definitely doesn't seem to work:

import 'imba-router'

import {Home} from './home'
import {Friends} from './friends/index'

tag App

	def build 
                # trying to setup a listener for either the change and beforechange events... but doesn't work
		self.router.on('beforechange') do |req|
			console.log 'beforechange'
		self.router.on('change') do |req|
			console.log 'change'
                # setting the hash mode does indeed work
		self.router.mode = 'hash'
		
	def render
		<self.vbox>
			<header>
				<a route-to='/'> "Home"
				<a route-to='/friends'> "Friends"
			<div.section>
				<Home route='/'>
				<Friends route='/friends'>

Imba.mount <App>

Thanks in advance for your help into solving this issue!

dragonautdev avatar Dec 02 '18 03:12 dragonautdev