/**
 * Simple client-side router
 * @module riot-route
 */

var observable = require('riot-observable')

var EVT = 'hashchange', win = window, loc = win.location, started = false, fns = observable(), current

/**
 * Get hash part of current URL
 * @returns {string} hash string
 */
function hash() {
  return loc.href.split('#')[1] || '' // why not loc.hash.splice(1) ?
}

/**
 * Default parser. You can replace it via router.parser method.
 * @param {string} path - current path
 * @returns {*} array or object as you like
 */
function parser(path) {
  return path.split('/')
}

function emit(path) {
  if (path.type) path = hash()

  if (path != current) {
    fns.trigger.apply(null, ['H'].concat(parser(path)))
    current = path
  }
}

var route = function(arg) {
  // string
  if (arg[0]) {
    loc.hash = arg
    emit(arg)

  // function
  } else {
    fns.on('H', arg)
  }
}

/**
 * Exec routing right now
 * @param {function} fn - your action
 */
route.exec = function(fn) {
  fn.apply(null, parser(hash()))
}

/**
 * Replace the default router to yours
 * @param {function} fn - your parser function
 */
route.parser = function(fn) {
  parser = fn
}

/** Stop routing **/
route.stop = function () {
  if (started) {
    win.removeEventListener(EVT, emit, false)
    fns.off('*')
    started = false
  }
}

/** Start routing **/
route.start = function () {
  if (!started) {
    win.addEventListener(EVT, emit, false)
    started = true
  }
}

/** Autostart the router **/
route.start()

module.exports = route

@@ -213,21 +213,16 @@
 %0A * Get 
-hash 
 part of 
@@ -232,16 +232,49 @@
 rent URL
+ which contains the router params
 %0A * @ret
@@ -343,59 +343,389 @@
 ref.
-split('#')%5B1%5D %7C%7C '' // why not loc.hash.splic
+replace(root(), '')%0A%7D%0A%0A/**%0A * Get root path of the router's app%0A * @return %7Bstring%7D app root%0A */%0Afunction root() %7B%0A  var matches = base.exec(loc.href)%0A  return matches ? matches%5B0%5D : loc.host%0A%7D%0A%0A/**%0A * Default RegExp for separate route params and app root path%0A * You can replace it via route.base method%0A * @return %7BRegExp%7D regular expression%0A */%0Afunction bas
 e(
-1
 ) 
-?
+%7B%0A  return /%5E.*#/
 %0A%7D%0A%0A
@@ -775,17 +775,16 @@
 ia route
-r
 .parser 
@@ -789,17 +789,16 @@
 r method
-.
 %0A * @par
@@ -1083,16 +1083,48 @@
  = path%0A
+    loc.href = root() + current%0A
   %7D%0A%7D%0A%0Av
@@ -1182,27 +1182,8 @@
 ) %7B%0A
-    loc.hash = arg%0A
     
@@ -1378,24 +1378,150 @@
 hash()))%0A%7D%0A%0A
+/**%0A * Replace the default base to yours%0A * @param %7BRegExp%7D regular expression%0A */%0Aroute.base = function(re) %7B%0A  base = re%0A%7D%0A%0A
 /**%0A * Repla

add base method