Generally, the user enters the website through the home page and then I render the sidebar view there. Next, the user clicks a link and the router renders another view and replaces the original content view. The sidebar view is not re-rendered.
When the user clicks refresh while on a sub-page, the sidebar is not rendered.
How do I check whether a view exists and has been rendered?
Split the responsibilities and stick to it. Don't put the sidebar rendering into the hands of the home page view.
You could have a layout view which handles rendering the content, header, footer and sidebar. Then, when the user navigate to another page, the router just calls something like
setContent(view)
on the layout view, which makes sure the sidebar (and everything else) was rendered before rendering the content.Assuming this template:
The layout view could be as simple as:
And the router could lazily create views: