Skip to content

Commit

Permalink
feat(router): add upwards scope traversal feat to link
Browse files Browse the repository at this point in the history
  • Loading branch information
jwx committed Aug 16, 2019
1 parent 7be6e9d commit 8b32b3b
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,25 +162,24 @@ export class Router implements IRouter {
let href = info.href;
if (href.startsWith('#')) {
href = href.slice(1);
// '#' === '/' === '#/'
if (!href.startsWith('/')) {
href = `/${href}`;
}
}
// If it's not from scope root, figure out which scope
if (!href.startsWith('/')) {
let scope = this.closestScope(info.anchor);
// No scope modifications, default to include current scope
// and replace content (by moving start one scope up)
if (!href.startsWith('.')) {
scope = scope.parent || scope;
} else {
// Start in current scope and look down (don't replace content)
// Scope modifications
if (href.startsWith('.')) {
// The same as no scope modification
if (href.startsWith('./')) {
href = href.slice(2);
} else { // Find out how many scopes upwards we should move
// First move up to include the current scope
}
// Find out how many scopes upwards we should move
while (href.startsWith('../')) {
scope = scope.parent || scope;
while (href.startsWith('../')) {
scope = scope.parent || scope;
href = href.slice(3);
}
href = href.slice(3);
}
}
const context = scope.scopeContext();
Expand Down

0 comments on commit 8b32b3b

Please sign in to comment.