0

I got 2 divs, first has links pointing to individual pages and another one to display the content of pages the links are pointing to. Here is how it looks:

<div id="navigation">
   <a href="http://mydomain/page1">
   <a href="http://mydomain/page2">
   <a href="http://mydomain/and-so-on">
</div>

<div id="content">
   <!-- display content here -->
</div>

Is there a way to prevent redirecting the page on link click and display the content of the URL they point to? I'm doing it this way for SEO purposes so each individual pages can also be crawlable on their own.

I've heard of ng-include but I want to be sure I'm heading the right direction so I reckon I should ask first before going with it.

Thank you in advance.

2
  • You can use an iframe and set the link's href as iframe's src. Commented Jul 29, 2017 at 6:57
  • Thanks. I prefer it the Angular way but I really do appreciate your feedback. Commented Jul 29, 2017 at 7:34

1 Answer 1

0

Use AngularJS Routing for this purpose.

    <a href="#page1">
    <a href="#page2">
    <a href="#and-so-on">


    <div ng-view></div>

    <script>
    var app = angular.module("myApp", ["ngRoute"]);
    app.config(function($routeProvider) {
        $routeProvider
        .when("page1", {
            templateUrl : "http://yourDomain/page1.html"
        })
        .when("/page2", {
            templateUrl : "http://yourDomain/page2.html"
        })
        .when("/and-so-on", {
            templateUrl : "http://yourDomain/and-so-on.html"
        });
    });
    </script>

Note: Must include angular-route.js

Sign up to request clarification or add additional context in comments.

2 Comments

Is it possible to use the full URL on the links instead? The page acts as a sitemap, if I may add.
No need to do that because you've mentioned the full URL in templateUrl

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.