1

I have an AngularJS application which has multiple apps. I've broken apart the single-page paradigm to 1) get server-side SEO urls and 2) to keep each app more modular.

I'd like to perform an in-page refresh IF the current app includes the route I'd like to go to. However, if the new route crosses between apps, I'd like to do an "absolute" redirect. I don't like the idea of configuring all possible routes, to test if an app is "crossed boundaries".

One solution I've been researching is testing the router to see if a route exists. If it doesn't then do an absolute redirect.

Is this a good solution, and if so - how to inspect the existing routes? I suspect this happens a lot with Express/NodeJS apps.

I am using ngRoute module.

Thanks!

3
  • Hi Charlie, you can get around the SEO issues using prerender.io, the solution you have is okay but would probably want to have a whitelist of paths that it should redirect so you can still deal with a bad path. Commented Apr 22, 2015 at 21:18
  • I checked into prerender.io, but this is overkill for what I'm trying to accomplish and adds more complexity than I want. Commented Apr 22, 2015 at 21:26
  • It's honestly simpler than it seems. You setup a redirect configuration in your server to send bots/crawlers to the prerendered version of the page. If you use their service that's all you need to do. If you'd rather run the prerender service yourself it basically uses PhantomJS to render your page and waits for async requests to load and sends that snapshot to the crawlers. Commented Apr 22, 2015 at 21:29

1 Answer 1

2

I found this: check $route.routes for existence of route. If missing, do an absolute redirect, otherwise do an in-page ($location.path()).

(One) solution looks like this.

this.ChangePathAcrossApps = function(newpage) {
    if ($route.routes[newpage]) {
        $location.path(newpage);
    } else {
        document.location = '/#' + newpage;
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

did you find any better solution?
No, I ended up using the above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.