---
title: "Keep or discard a draft through a navigation guard"
description: "Verify an unsaved-change guard supports staying on the editor and explicitly leaving without persisting the abandoned draft."
canonical_url: "https://vostride.com/agent-library/navigation-routing/unsaved-route-guard.md"
md_url: "https://vostride.com/agent-library/navigation-routing/unsaved-route-guard.md"
content_kind: "recipe"
topic: "navigation-routing"
---

# Keep or discard a draft through a navigation guard

Verify an unsaved-change guard supports staying on the editor and explicitly leaving without persisting the abandoned draft.

## Risk

A route guard can show a confirmation but still navigate behind it, or discard the draft even after the user chooses Stay. Both branches need observable data and location assertions.

## Fixtures

- A disposable note has saved body Original route guard text and an editor that guards internal navigation when dirty.
- The destination is the Notes index, and the product offers explicit Stay and Leave actions.
- A prepared read-only record check can confirm the saved body independently of the editor draft.

## Steps

1. Open the note editor, replace the body with Unsaved route guard draft, and do not save.
2. Activate the Notes navigation link and verify an unsaved-change confirmation appears.
3. Choose Stay and verify the editor remains open with the complete unsaved draft intact.
4. Activate the same navigation link again, choose Leave, and verify the Notes index opens.
5. Reopen the note and verify Original route guard text remains, corroborated by the prepared saved-record check.

## Expected results

- Stay cancels navigation and preserves the local unsaved draft.
- Leave reaches the intended destination while discarding the draft under this contract.
- The persisted note body never changes during either branch of the guard journey.

## False-pass traps

- A confirmation dialog alone does not prove navigation was blocked until a choice.
- Saving the draft before testing Leave would avoid the discard behavior entirely.

## Cleanup

- Delete the disposable note or restore its original body if an unexpected save occurred.

## Use with agent-qa

Adapt this test design to your application's acceptance criteria and configured target using the [recipe execution guide](/agent-library/software-factory/turn-a-recipe-into-an-agent-qa-test.md). External fixture setup and non-UI checks require your own supported hooks or test tooling. Validate the authored test, execute it, and inspect the completed evidence; this recipe is not a recorded test result.

## References

- [agent-qa test](/docs/agent-qa/configuration/test.md)
- [agent-qa first test](/docs/agent-qa/guides/first-test.md)
- [agent-qa web testing](/docs/agent-qa/guides/web-testing.md)

- [Navigation and routing QA recipes](/agent-library/navigation-routing.md)
- [Software factory QA library](/agent-library.md)
