fix(router): sort possible routes by cost
This commit is contained in:
@@ -23,6 +23,7 @@ export function main() {
|
||||
recognizer.addConfig('/test', handler);
|
||||
|
||||
expect(recognizer.recognize('/test')[0]).toEqual({
|
||||
'cost' : 1,
|
||||
'handler': { 'components': { 'a': 'b' } },
|
||||
'params': {},
|
||||
'matchedUrl': '/test',
|
||||
@@ -34,6 +35,7 @@ export function main() {
|
||||
recognizer.addConfig('/', handler);
|
||||
|
||||
expect(recognizer.recognize('/')[0]).toEqual({
|
||||
'cost': 0,
|
||||
'handler': { 'components': { 'a': 'b' } },
|
||||
'params': {},
|
||||
'matchedUrl': '/',
|
||||
@@ -44,6 +46,7 @@ export function main() {
|
||||
it('should work with a dynamic segment', () => {
|
||||
recognizer.addConfig('/user/:name', handler);
|
||||
expect(recognizer.recognize('/user/brian')[0]).toEqual({
|
||||
'cost': 101,
|
||||
'handler': handler,
|
||||
'params': { 'name': 'brian' },
|
||||
'matchedUrl': '/user/brian',
|
||||
@@ -57,6 +60,7 @@ export function main() {
|
||||
var solutions = recognizer.recognize('/a');
|
||||
expect(solutions.length).toBe(1);
|
||||
expect(solutions[0]).toEqual({
|
||||
'cost': 1,
|
||||
'handler': handler,
|
||||
'params': {},
|
||||
'matchedUrl': '/b',
|
||||
|
||||
@@ -27,6 +27,24 @@ export function main() {
|
||||
expect(instruction.getChildInstruction('default').component).toBe(DummyCompB);
|
||||
});
|
||||
|
||||
it('should prefer static segments to dynamic', () => {
|
||||
registry.config(rootHostComponent, {'path': '/:site', 'component': DummyCompB});
|
||||
registry.config(rootHostComponent, {'path': '/home', 'component': DummyCompA});
|
||||
|
||||
var instruction = registry.recognize('/home', rootHostComponent);
|
||||
|
||||
expect(instruction.getChildInstruction('default').component).toBe(DummyCompA);
|
||||
});
|
||||
|
||||
it('should prefer dynamic segments to star', () => {
|
||||
registry.config(rootHostComponent, {'path': '/:site', 'component': DummyCompA});
|
||||
registry.config(rootHostComponent, {'path': '/*site', 'component': DummyCompB});
|
||||
|
||||
var instruction = registry.recognize('/home', rootHostComponent);
|
||||
|
||||
expect(instruction.getChildInstruction('default').component).toBe(DummyCompA);
|
||||
});
|
||||
|
||||
it('should match the full URL recursively', () => {
|
||||
registry.config(rootHostComponent, {'path': '/first', 'component': DummyParentComp});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user