mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 02:54:21 +08:00
This enhancement eliminates the dependency on file extensions for server-side rendering (SSR) route handling, leveraging Angular's router configuration for more dynamic and flexible route determination. Additionally, configured redirectTo routes now correctly respond with a 302 redirect status. The new router uses a radix tree for storing routes. This data structure allows for efficient prefix-based lookups and insertions, which is particularly crucial when dealing with nested and parameterized routes. This change also lays the groundwork for potential future server-side routing configurations, further enhancing the capabilities of Angular's SSR functionality.
94 lines
3.6 KiB
TypeScript
94 lines
3.6 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.dev/license
|
|
*/
|
|
|
|
import { joinUrlParts, stripIndexHtmlFromURL, stripTrailingSlash } from '../../src/utils/url'; // Adjust the import path as needed
|
|
|
|
describe('URL Utils', () => {
|
|
describe('stripTrailingSlash', () => {
|
|
it('should remove trailing slash from URL', () => {
|
|
expect(stripTrailingSlash('/path/')).toBe('/path');
|
|
});
|
|
|
|
it('should not modify URL if no trailing slash is present', () => {
|
|
expect(stripTrailingSlash('/path')).toBe('/path');
|
|
});
|
|
|
|
it('should handle empty URL', () => {
|
|
expect(stripTrailingSlash('')).toBe('');
|
|
});
|
|
|
|
it('should handle URL with only a trailing slash', () => {
|
|
expect(stripTrailingSlash('/')).toBe('');
|
|
});
|
|
});
|
|
|
|
describe('joinUrlParts', () => {
|
|
it('should join multiple URL parts with normalized slashes', () => {
|
|
expect(joinUrlParts('', 'path/', '/to/resource')).toBe('/path/to/resource');
|
|
});
|
|
|
|
it('should handle URL parts with leading and trailing slashes', () => {
|
|
expect(joinUrlParts('/', '/path/', 'to/resource/')).toBe('/path/to/resource');
|
|
});
|
|
|
|
it('should handle empty URL parts', () => {
|
|
expect(joinUrlParts('', '', 'path', '', 'to/resource')).toBe('/path/to/resource');
|
|
});
|
|
});
|
|
|
|
describe('stripIndexHtmlFromURL', () => {
|
|
it('should remove /index.html from the end of the URL path', () => {
|
|
const url = new URL('http://www.example.com/page/index.html');
|
|
const result = stripIndexHtmlFromURL(url);
|
|
expect(result.href).toBe('http://www.example.com/page');
|
|
});
|
|
|
|
it('should not modify the URL if /index.html is not present', () => {
|
|
const url = new URL('http://www.example.com/page');
|
|
const result = stripIndexHtmlFromURL(url);
|
|
expect(result.href).toBe('http://www.example.com/page');
|
|
});
|
|
|
|
it('should handle URLs without a path', () => {
|
|
const url = new URL('http://www.example.com/index.html');
|
|
const result = stripIndexHtmlFromURL(url);
|
|
expect(result.href).toBe('http://www.example.com/');
|
|
});
|
|
|
|
it('should not modify the URL if /index.html is in the middle of the path', () => {
|
|
const url = new URL('http://www.example.com/index.html/page');
|
|
const result = stripIndexHtmlFromURL(url);
|
|
expect(result.href).toBe('http://www.example.com/index.html/page');
|
|
});
|
|
|
|
it('should handle URLs with query parameters and /index.html at the end', () => {
|
|
const url = new URL('http://www.example.com/page/index.html?query=123');
|
|
const result = stripIndexHtmlFromURL(url);
|
|
expect(result.href).toBe('http://www.example.com/page?query=123');
|
|
});
|
|
|
|
it('should handle URLs with a fragment and /index.html at the end', () => {
|
|
const url = new URL('http://www.example.com/page/index.html#section');
|
|
const result = stripIndexHtmlFromURL(url);
|
|
expect(result.href).toBe('http://www.example.com/page#section');
|
|
});
|
|
|
|
it('should handle URLs with both query parameters and fragments and /index.html at the end', () => {
|
|
const url = new URL('http://www.example.com/page/index.html?query=123#section');
|
|
const result = stripIndexHtmlFromURL(url);
|
|
expect(result.href).toBe('http://www.example.com/page?query=123#section');
|
|
});
|
|
|
|
it('should handle URLs with HTTPS scheme and /index.html at the end', () => {
|
|
const url = new URL('https://www.example.com/page/index.html');
|
|
const result = stripIndexHtmlFromURL(url);
|
|
expect(result.href).toBe('https://www.example.com/page');
|
|
});
|
|
});
|
|
});
|