In-depth Guide - setting application route and env


#1

Hi everybody,
I would like to start a new project with DoneJS and I’m diving in the in-depth guide, but i’m stuck because i don’t understand how the routing works.

In the example (using done-serve) the route.register is called without setting the route.data before:

const AppViewModel = DefineMap.extend({
  page: 'string',
  slug: 'string',
  action: 'string',
  
   // env: {
   //   default: () => { return {NODE_ENV:'development'}; },
   //   serialize: false
//},

  title: {
    default: 'place-my-order',
    serialize: false
  }
});

route.register('{page}', { page: 'home' });
route.register('{page}/{slug}', { slug: null });
route.register('{page}/{slug}/{action}', { slug: null, action: null });

export default AppViewModel;

And it works well but i cannot figure out how.
But, it I don’t use the done-serve, and i set up a Express server using done-ssr-middleware I get that the prop page is not defined in the the viewModel.

In addition, I got problem with the env status added in the viewModel. When I uncomment the env definition, i get the following error:

TypeError: Cannot define property statusCode, object is not extensible
at Function.defineProperty ()
at Object_defineNamedPrototypeProperty (file:/home/fra/Projects/donejs_indepth/place-my-order/node_modules/can-define/can-define.js:51:16)
at Function.define.property (file:/home/fra/Projects/donejs_indepth/place-my-order/node_modules/can-define/can-define.js:352:2)
at Object.defineExpando (file:/home/fra/Projects/donejs_indepth/place-my-order/node_modules/can-define/define-helpers/define-helpers.js:31:11)
at DefineMap.setKeyValue (file:/home/fra/Projects/donejs_indepth/place-my-order/node_modules/can-define/map/map.js:52:30)
at Object.setKeyValue (file:/home/fra/Projects/donejs_indepth/place-my-order/node_modules/can-reflect/reflections/get-set/get-set.js:49:23)
at createViewModelAndRender (file:/home/fra/Projects/donejs_indepth/place-my-order/src/index.stache:425:16)
at /home/fra/Projects/donejs_indepth/place-my-order/node_modules/done-ssr/zones/steal/load.js:67:9
at /home/fra/Projects/donejs_indepth/place-my-order/node_modules/can-zone/lib/tasks.js:162:15
at Task.run (/home/fra/Projects/donejs_indepth/place-my-order/node_modules/can-zone/lib/zone.js:38:17)
at Zone.runTask (/home/fra/Projects/donejs_indepth/place-my-order/node_modules/can-zone/lib/zone.js:181:14)

Any suggestions?
Thanks


#2

Hi @fp_dev,

route.register is called without setting the route.data before

This is done automatically by done-autorender which is why you don’t have to do it yourself.

TypeError: Cannot define property statusCode, object is not extensible

This error happens when trying to set a property on a sealed object, which can-define/map/map is by default. I think it’ll work correctly if you define statusCode on your AppViewModel.