Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ and this project adheres to Semantic Versioning.
- [Fixed (1.3.0)](#fixed-130)
- [[1.2.0] - 2026-01-24](#120---2026-01-24)
- [Added (1.2.0)](#added-120)
- [(1.1.2) - 2026-01-24](#112---2026-01-24)
- [[1.1.2] - 2026-01-24](#112---2026-01-24)
- [Fixed (1.1.2)](#fixed-112)
- [Security (1.1.2)](#security-112)
- [(1.1.1) - 2026-01-24](#111---2026-01-24)
- [[1.1.1] - 2026-01-24](#111---2026-01-24)
- [Fixed (1.1.1)](#fixed-111)
- [(1.1.0) - 2026-01-23](#110---2026-01-23)
- [[1.1.0] - 2026-01-23](#110---2026-01-23)
- [Added (1.1.0)](#added-110)
- [Changed (1.1.0)](#changed-110)
- [Security (1.1.0)](#security-110)
- [(1.0.2) - 2026-01-23](#102---2026-01-23)
- [[1.0.2] - 2026-01-23](#102---2026-01-23)
- [Fixed (1.0.2)](#fixed-102)
- [(1.0.1) - 2026-01-23](#101---2026-01-23)
- [[1.0.1] - 2026-01-23](#101---2026-01-23)
- [Fixed (1.0.1)](#fixed-101)
- [(1.0.0) - 2026-01-21](#100---2026-01-21)
- [[1.0.0] - 2026-01-21](#100---2026-01-21)
- [Added (1.0.0)](#added-100)

## [1.3.0] - 2026-01-26
Expand Down Expand Up @@ -98,7 +98,7 @@ and this project adheres to Semantic Versioning.
- Custom directive prefix support.
- Automatic HTML sanitization for security.

## (1.1.2) - 2026-01-24
## [1.1.2] - 2026-01-24

### Fixed (1.1.2)

Expand All @@ -108,13 +108,13 @@ and this project adheres to Semantic Versioning.

- Added `rel="noopener noreferrer"` to external links for improved security.

## (1.1.1) - 2026-01-24
## [1.1.1] - 2026-01-24

### Fixed (1.1.1)

- Fixed a possibly dangrous html handling in the playground examples.
- Fixed a possibly dangerous html handling in the playground examples.

## (1.1.0) - 2026-01-23
## [1.1.0] - 2026-01-23

### Added (1.1.0)

Expand Down Expand Up @@ -152,13 +152,13 @@ and this project adheres to Semantic Versioning.
- Added protection against DOM clobbering attacks by preventing reserved IDs like `document`, `cookie`, `location`.
- Improved URL sanitization to prevent Unicode bypass attacks using zero-width characters.

## (1.0.2) - 2026-01-23
## [1.0.2] - 2026-01-23

### Fixed (1.0.2)

- Fixed brodken documentation links in README.md.
- Fixed broken documentation links in README.md.

## (1.0.1) - 2026-01-23
## [1.0.1] - 2026-01-23

### Fixed (1.0.1)

Expand All @@ -167,7 +167,7 @@ and this project adheres to Semantic Versioning.
- Revised the homepage URL in `package.json` to point to the official bQuery website.
- Added publish configuration in `package.json` to ensure public accessibility on npm registry.

## (1.0.0) - 2026-01-21
## [1.0.0] - 2026-01-21

### Added (1.0.0)

Expand Down
4 changes: 2 additions & 2 deletions src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const createRouter = (options: RouterOptions): Router => {
const beforeGuards: NavigationGuard[] = [];
const afterHooks: Array<(to: Route, from: Route) => void> = [];

// Flatten nested routes
const flatRoutes = flattenRoutes(routes, base);
// Flatten nested routes (base-relative, not including the base path)
const flatRoutes = flattenRoutes(routes);

/**
* Gets the current path from the URL.
Expand Down
5 changes: 3 additions & 2 deletions src/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import type { RouteDefinition } from './types';

/**
* Flattens nested routes into a single array with full paths.
* Does NOT include the router base - base is only for browser history.
* @internal
*/
export const flattenRoutes = (routes: RouteDefinition[], base = ''): RouteDefinition[] => {
export const flattenRoutes = (routes: RouteDefinition[], parentPath = ''): RouteDefinition[] => {
const result: RouteDefinition[] = [];

for (const route of routes) {
const fullPath = route.path === '*' ? '*' : `${base}${route.path}`.replace(/\/+/g, '/');
const fullPath = route.path === '*' ? '*' : `${parentPath}${route.path}`.replace(/\/+/g, '/');

result.push({
...route,
Expand Down
9 changes: 4 additions & 5 deletions src/view/directives/if.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { DirectiveHandler } from '../types';
* @internal
*/
export const handleIf: DirectiveHandler = (el, expression, context, cleanups) => {
const parent = el.parentNode;
const placeholder = document.createComment(`bq-if: ${expression}`);

// Store original element state
Expand All @@ -17,12 +16,12 @@ export const handleIf: DirectiveHandler = (el, expression, context, cleanups) =>
const condition = evaluate<boolean>(expression, context);

if (condition && !isInserted) {
// Insert element
parent?.replaceChild(el, placeholder);
// Insert element using replaceWith to handle moved elements
placeholder.replaceWith(el);
isInserted = true;
} else if (!condition && isInserted) {
// Remove element
parent?.replaceChild(placeholder, el);
// Remove element using replaceWith to handle moved elements
el.replaceWith(placeholder);
isInserted = false;
}
});
Expand Down
5 changes: 3 additions & 2 deletions tests/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ describe('Router', () => {
expect(stack[stack.length - 1].url).toBe('/app/page');
});

it('should flatten nested routes with base path', () => {
it('should flatten nested routes without including base path', () => {
router = createRouter({
routes: [
{
Expand All @@ -1276,7 +1276,8 @@ describe('Router', () => {
});

expect(router.routes).toHaveLength(2);
expect(router.routes[1].path).toBe('/app/parent/child');
// Routes should not include base - base is only for browser history
expect(router.routes[1].path).toBe('/parent/child');
});
});

Expand Down
Loading