首页 > 解决方案 > 单击链接时Angularjs ui-view路由不起作用

问题描述

当我点击 lick 时,我在这里使用 Angular ui-routing 功能 url 在 url bar 中扩展 像这样

AngularCtrl 是

    var app = angular.module('MyApp', ['ui.router'])
app.config(['$qProvider', '$stateProvider', function ($qProvider, $stateProvider) {
    $qProvider.errorOnUnhandledRejections(false);
    var Custstate = {
        name: 'Customer',
        url: 'Views/Customer/Customer.html',
    }
    $stateProvider.state(Custstate);
}])

ui-view 是

 <a ui-sref="Customer" ui-sref-active="active">Customer</a>
    <ui-view></ui-view>

标签: angularjsangular-ui-router

解决方案


在这样的配置注册状态。

var routerApp = angular.module('MyApp', ['ui.router']);

routerApp.config(function($stateProvider, $urlRouterProvider) {
    $stateProvider
    .state('Customer', {
        url: '/Customer',
        templateUrl: 'Views/Customer/Customer.html'
    });

});

有关更多详细信息,请参阅https://scotch.io/tutorials/angular-routing-using-ui-router


推荐阅读