Aurelia layout is recreated on every route change -


background

i have typical web app left column menu; , right column content.

if put menu in left column , use <router-view></router-view> in right, expect content swapped out navigate routes.

see basic gist.run here. not actual app ignore oversimplifications. can see clicking on 1 of menu items changes style, click 1 of home/page links , menu item keeps applied class.

the problem

if add layout these 2 routes, menu looses state when changing routes. i.e. applied "active" style lost because layout reloaded, instead of slot being reloaded. gist.run here:
app.js:

config.map([   { route: '', name: 'home', moduleid: 'home', layoutview: "layout.html", layoutviewmodel: "layout" },   { route: 'page', name: 'page', moduleid: 'page', layoutview: "layout.html", layoutviewmodel: "layout" } ]); 

layout.html:

<template>   <!-- left menu content here -->   <div class="layout">   <!-- route view on right: -->     <slot></slot>   </div> </template> 

my home.html , route.html pages identical previous gist without layouts:

<template>   home </template> 

note slots not needed here (e.g. <div slot="name">...) because there 1 slot. i've tried including them , result same.

i expect layout/router behaviour should same - layout isn't reloaded on each route change - though it's wired differently underneath.

this problem because may have animations on menu items (sliding, dropdowns, active classes etc.) , don't want starting default position each time route changed. may have controls in left panel such search box or other form, , may not want refreshing on each route change.

is there way can make layout behave same (keep "state") router-view?

as way around i've considered:

  • an initial state put current route (could messy or not cover options)
  • saving state in service or singleton somehow, can't figure out if possible view
  • router viewports. not quite flexible because can't have multiple different app.html's different viewports laid out in different ways. requires module-per-viewport or other trickery, , can't have content same view slots...

please tell me if there's else can or if i'm doing wrong!

thanks.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -