The code I am sharing isn’t from a widget, but it is from a component that we did release for download here on meta.
In it we use the router, along with @discourseComputed
to check if the route has changed, and render based on that.
You can look deeper into the code if you are interested in how it works.