swimlane / DocSPA

A documentation SPA in Angular.
https://swimlane.github.io/DocSPA/
MIT License
46 stars 10 forks source link

Update docspa-core.component.ts and router.sevice.ts #37

Closed gnu4cn closed 3 years ago

gnu4cn commented 3 years ago

Pass a snapshot is not need.

Hypercubed commented 3 years ago

Can you explain... looks like a required parameter of RouterService#activateRoute

gnu4cn commented 3 years ago

Can you explain... looks like a required parameter of RouterService#activateRoute

Exactly it's not need to pass a snapshot to the activateRoute method. I've test it. We can get all the information from the route url.

Hypercubed commented 3 years ago

That would require rewriting the activateRoute method:

  activateRoute(snapshot: ActivatedRouteSnapshot) {
    const url = snapshot.url.map(s => s.path).join('/');
    let root = this.router.url;
    if (snapshot.fragment) {
      root = root.replace(new RegExp('#' + snapshot.fragment + '$'), '');
    }
    root = root.replace(new RegExp(url + '$'), '');
    if (!root.endsWith('/')) {
      root += '/';
    }
    const path = url + (snapshot.fragment ? `#${snapshot.fragment}` : '');
    this.go(path, root);
  }
gnu4cn commented 3 years ago

In another request, I rewrote the method.

gnu4cn commented 3 years ago

I should make pull requests together.