ANGULARJS implementation of single page application principle-routing (route)

Source: Internet
Author: User

ANGULARJS implementation of single page application principle-routing (route)

Routing: tells you a path to a specific page

Http://127.0.0.1/index.html#/start

Http://127.0.0.1/index.html#/main

#/start <=> start.html

#/main <=> main.html

The principle of page switching in a spa app:

(1) Use JS to parse the current page address Location.hash ()

(2) Find the dictionary and find the true page name for the specified routing address

(3) Initiate an asynchronous Ajax request to read the contents of the target page and load it to the current page at the specified location

Routing modules in Angularjs-for "pseudo-page transition effects" in spa applications

Steps:

(1) Introduction of Angular.js and Angular-route.js in index.html

(2) the page declares a container with Ngview directive: <div ng-view></div>

(3) Create Module declaration module dependent on Ngroute module

Angular.module (' module name ', [' ngroute ', ' ng '])

(4) Configure the mapping information for the routing address:

. config (function ($routeProvider) {

$routeProvider. When ('/routing address ', {templateurl: ' pseudo page address '})

} )

(5) Test: Enter http://...../index.html#/routing address in the address bar

Love Card (Shenzhen) Management Co., Ltd.

Share every moment of a wonderful

: Icafeyojoy

Weibo:Http://weibo.com/iCafeYOJOY

Official website:www.icafe.im

ANGULARJS implementation of single page application principle-routing (route)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.