cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              h1 Z-router

ul
  li
    a(href="#/") home
  li
    a(href="#/user") user
  li
    a(href="#/user/42") users/42

#z-router-view
            
          
!
            
              *, *:before, *:after
  margin: 0
  padding: 0
  box-sizing: border-box
html
  font-size: 20px
body
  font-family: sans-serif
  color: #444
  margin: 1rem 2rem

ul
  display: block
  li
    display: inline-block
    list-style-type: none
    margin: .5rem
    a
      display: inline-block
      padding: .6em 1em
      background: #eee
      border-radius: .3em
      color: inherit
      text-decoration: none
      &:hover
        background: #AAA
#z-router-view
  padding: 1em
  border: .2em solid #444
  margin: 1em 0 
        
            
          
!
            
              //Z-router script
var ZRouter=function(e,t){var r={routes:[],root:"/",el:"#z-router-view",loaderTpl:"<p>Loading...</p>",getTemplate:function(e){if(e.template)n.render(r.tp(e.template,e.options)),"function"==typeof e.callback&&e.callback(e.options);else if(e.templateUrl){n.render(r.loaderTpl);var t=new XMLHttpRequest;t.onreadystatechange=function(){4==t.readyState&&200==t.status?(e.template=t.responseText,n.render(r.tp(t.responseText,e.options)),"function"==typeof e.callback&&e.callback(e.options)):404==t.status&&n.render("<h1>Error "+t.status+"</h1>")},t.open("GET",e.templateUrl,!0),t.send()}},getFragment:function(){""===t.location.hash&&(t.location.hash="#"+r.root);var e=t.location.href.match(/#(.*)$/),n=e?e[1]:"";return n.toString()},tp:function(e,t){for(var r,n=/<%([^%>]+)?%>/g,o=/(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g,a="var r=[];\n",l=0,c=function(e,t){return a+=t?e.match(o)?e+"\n":"r.push("+e+");\n":""!==e?'r.push("'+e.replace(/"/g,'\\"')+'");\n':"",c};r=n.exec(e);)c(e.slice(l,r.index))(r[1],!0),l=r.index+r[0].length;return c(e.substr(l,e.length-l)),a+='return r.join("");',new Function(a.replace(/[\r\t\n]/g,"")).apply(t)}},n={setRoot:function(e){return r.root=e,n},setLoaderTpl:function(e){return r.loaderTpl=e,n},add:function(e){return"object"==typeof e&&e.url&&(e.template||e.templateUrl)?r.routes.push(e):console.log("This route has a problem, it cant be added!",e),n},check:function(e){for(var t,o,a=e||r.getFragment(),l={},c=0;c<r.routes.length;c++){var i=r.routes[c],u=new RegExp("^"+i.url.replace(/(:\w+)/g,"([\\w-]+)")+"$");if(t=a.match(u)){if(t.shift(),o=i.url.match(/(:\w+)/g))for(var s=0;s<o.length;s++)l[o[s].slice(1)]=t[s];return i.options||(i.options={}),i.options.params=l,r.getTemplate(i),n}}return n.navigate(r.root),n},listen:function(){var e,t=null,o=function(){t!==r.getFragment()&&(t=r.getFragment(),n.check(t))};return clearInterval(e),e=setInterval(o,50),n},render:function(t){return e.querySelector(r.el).innerHTML=t,n},navigate:function(e){return e=e?e:"",t.location.href=t.location.href.replace(/#(.*)$/,"#"+e),n}};return n}(document,window);

//Router declaration

ZRouter
  .add({
  url: "/",
  template: "<h1>Home</h1><p>I am the home template</p>" 
  })
  .add({
  url: "/user",
  template: '<h1>User</h1><p>Here is the list of users</p> <ul><li><a href="#/user/1">user 1</a><li><li><a href="#/user/2">user 2</a><li></ul>'
  })
  .add({
  url: "/user/:id",
  template: "<h1>User <% this.params.id %></h1><p>Here is the user's <b><%this.params.id%></b> specific page!</p>" 
  })
  .listen();
            
          
!
999px
Loading ..................

Console