In the unofficial documentation, the best way to open a custom view is to first register the view:
this.registerView(
VIEW_TYPE_EXAMPLE,
(leaf) => new ExampleView(leaf)
);
And then activate the view:
async activateView() {
this.app.workspace.detachLeavesOfType(VIEW_TYPE_EXAMPLE);
await this.app.workspace.getRightLeaf(false).setViewState({
type: VIEW_TYPE_EXAMPLE,
active: true,
});
this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(VIEW_TYPE_EXAMPLE)[0]
);
}
but this solution doesn’t seem to fit my need( I need to pass in params ). I’m currently opening an ItemView from a prompt. And I’ve got the view appearing with my passed in parameters like such:
await this.app.workspace.getLeaf(false).setViewState({
type: VIEW_TYPE_EXAMPLE,
active: true
});
const leaf = this.app.workspace.getLeavesOfType(VIEW_TYPE_EXAMPLE)[0]
this.app.workspace.getLeaf().open(new TestItemView(leaf, params))
Notice I don’t have to register the view at all. I’m left wondering, is this an alright way to open a view? I tried setting the view state (setViewState) while implementing the original way, but was unable to actually retrieve the passed in values within the custom view.