Fix validation guard for router (#520)

This commit is contained in:
Fine0830
2026-02-05 18:01:05 +08:00
committed by GitHub
parent 41b323400f
commit 4e3b1bdeae
4 changed files with 8 additions and 18 deletions

View File

@@ -37,7 +37,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
node-version: [20.x, 22.x, 24.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}

View File

@@ -124,16 +124,6 @@ describe("Router Guards", () => {
expect(mockNext).toHaveBeenCalledWith();
});
it("should redirect to NotFound for routes with invalid parameters", () => {
const validationGuard = createValidationGuard();
const to = { path: "/invalid", params: { id: "", name: null } };
const from = { path: "/some-path" };
validationGuard(to, from, mockNext);
expect(mockNext).toHaveBeenCalledWith({ name: "NotFound" });
});
it("should redirect to NotFound for routes with undefined parameters", () => {
const validationGuard = createValidationGuard();
const to = { path: "/invalid", params: { id: undefined } };
@@ -144,14 +134,14 @@ describe("Router Guards", () => {
expect(mockNext).toHaveBeenCalledWith({ name: "NotFound" });
});
it("should handle mixed valid and invalid parameters", () => {
it("should allow empty or null parameters (only undefined is invalid)", () => {
const validationGuard = createValidationGuard();
const to = { path: "/mixed", params: { id: "123", name: "" } };
const to = { path: "/mixed", params: { id: "", name: null } };
const from = { path: "/some-path" };
validationGuard(to, from, mockNext);
expect(mockNext).toHaveBeenCalledWith({ name: "NotFound" });
expect(mockNext).toHaveBeenCalledWith();
});
});

View File

@@ -55,9 +55,7 @@ export function createValidationGuard() {
// Validate route parameters if needed
if (to.params && Object.keys(to.params).length > 0) {
// Add custom validation logic here
const hasValidParams = Object.values(to.params).every(
(param) => param !== undefined && param !== null && param !== "",
);
const hasValidParams = Object.values(to.params).every((param) => param !== undefined);
if (!hasValidParams) {
next({ name: "NotFound" });

View File

@@ -73,7 +73,9 @@ limitations under the License. -->
const currentPageModel = computed({
get: () => props.currentPage,
set: (val: number) => emits("update:currentPage", val),
set: (val: number) => {
void val;
},
});
const paginationStyle = computed(() => {