Angularjs page Jump route

Source: Internet
Author: User

ANGULAGJS pages use the route jump

1. In addition to referencing Angularjs.js, also refer to the route JS, "~/scripts/angularjs/angular-route.js"

2. Defining routes through $routeprovider, example

varTestmodule = Angular.module (' Testmodule ', [' Ngroute ']); Testmodule.config ([' $routeProvider ',function($routeProvider) {$routeProvider. When ('/2 ', {//'/2 ' defines a routing path that is later accessed through this path, usually defined as a short pathTemplateurl: "/home/index2",//"/home/index2" is the path to the actual route access, which can be an access path for ASP. NET MVC (in this case), but also a specific page path, such as "test/test.html"Controller: ' TestController '//The controller that routes the jump, which must be defined later    }); $routeProvider. When ('/3 ', {templateurl:"/home/index3", Controller:' TestController '    })}]);

3. Use route jump, combine Ng-view to do spa

3.1 Use $location to jump in JS, as an example, call GoToIndex2 when needed

function ($scope, $location) {    function  () {        $location. Path ("/2")    }}]);

3.2 Use href= "#path" in HTML code to jump

<HTML><Head>    <Metaname= "Viewport"content= "Width=device-width" />    <title>Index1</title>@Styles. Render ("~/content/css/base") @Scripts. Render ("~/script/base")<Scriptsrc= "~/scripts/ngmoudle/app.js"></Script></Head><Body>    <DivNg-app= "Testmodule"Ng-controller= "TestController">        <Header>            <H1>This is INDEX1</H1>            <Buttontype= "button"class= "Btn Btn-default"Ng-click= "GoToIndex2 ()">Index2</Button>            <ahref= "#/3"class= "Btn Btn-default">Index3</a><!--Jump by heft= "#path" Way -            <ahref= "#/2"class= "Btn Btn-default" >Index2</a>               </Header>        <DivNg-view>        </Div>        <Footer>PAGE FOOTER</Footer>    </Div></Body></HTML>

Angularjs page Jump 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.