[BUGFIX beta] Do not attempt to serialize undefined models.

If a routes model is undefined do not attempt to serialize it.

Previously, this would cause an error like: `Cannot call get with 'id' on an undefined object.`.

Resolves #3859.