本文介绍了角2路由器没有基础的href集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个错误,找不到原因。以下是错误:

 例外:LocationStrategy的实例化时出错! (RouterOutlet  - >路由器 - >位置 - > LocationStrategy)。
    angular2.dev.js:23514例外:LocationStrategy的实例化时出错! (RouterOutlet - >路由器 - >位置 - > LocationStrategy).BrowserDomAdapter.logError @ angular2.dev.js:23514BrowserDomAdapter.logGroup @ angular2.dev.js:23525ExceptionHandler.call @ angular2.dev.js:1145(匿名函数)@ angular2.dev.js:14801NgZone._notifyOnError @ angular2.dev.js:5796collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:5700run @ angular2-polyfills.js:141(匿名函数)@ angular2.dev。 JS:5719zoneBoundFn @ angular2-polyfills.js:111lib $ ES6 $承诺$$内部$$ tryCatch @ angular2-polyfills.js:1511lib $ ES6 $承诺$$内部$$ invokeCallback @ angular2-polyfills.js:1523lib $ ES6 $承诺$$内部$$发布@ angular2-polyfills.js:1494(匿名函数)@ angular2-polyfills.js:243microtask @ angular2.dev.js:5751run @ angular2-polyfills.js:138(匿名函数)@ angular2。 dev.js:5719zoneBoundFn @ angular2-polyfills.js:111lib $ ES6 $ $答应尽快$$平齐@ angular2-polyfills.js:1305
    angular2.dev.js:23514原始异常:无基本href集。请提供APP_BASE_HREF令牌的值或基本元素添加到document.BrowserDomAdapter.logError @ angular2.dev.js:23514ExceptionHandler.call @ angular2.dev.js:第1154(匿名函数)@ angular2.dev.js:14801NgZone ._notifyOnError @ angular2.dev.js:5796collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:5700run @ angular2-polyfills.js:141(匿名函数)@ angular2.dev.js:5719zoneBoundFn @ angular2,polyfills.js :111lib $ ES6 $承诺$$内部$$ tryCatch @ angular2-polyfills.js:1511lib $ ES6 $承诺$$内部$$ invokeCallback @ angular2-polyfills.js:1523lib $ ES6 $承诺$$内部$$发布@ angular2 -polyfills.js:1494(匿名函数)@ angular2-polyfills.js:243microtask @ angular2.dev.js:5751run @ angular2-polyfills.js:138(匿名函数)@ angular2.dev.js:5719zoneBoundFn @ angular2,polyfills .js文件:111lib $ ES6 $承诺尽快$ $$平齐@ angular2-polyfills.js:1305
    angular2.dev.js:23514 ORIGINAL堆栈跟踪:BrowserDomAdapter.logError @ angular2.dev.js:23514ExceptionHandler.call @ angular2.dev.js:第1157(匿名函数)@ angular2.dev.js:14801NgZone._notifyOnError @ angular2.dev。 JS:5796collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:5700run @ angular2-polyfills.js:141(匿名函数)@ angular2.dev.js:5719zoneBoundFn @ angular2-polyfills.js:111lib $ ES6 $ $承诺$内部$$ tryCatch @ angular2-polyfills.js:1511lib $ ES6 $承诺$$内部$$ invokeCallback @ angular2-polyfills.js:1523lib $ ES6 $承诺$$内部$$发布@ angular2-polyfills.js:1494(匿名函数)@ angular2-polyfills.js:243microtask @ angular2.dev.js:5751run @ angular2-polyfills.js:138(匿名函数)@ angular2.dev.js:5719zoneBoundFn @ angular2-polyfills.js:111lib $ ES6 $答应尽快$ $$平齐@ angular2-polyfills.js:1305
    angular2.dev.js:23514错误:没有基本href集。请提供APP_BASE_HREF令牌的值或碱元素添加到文档中。
        在新BaseException(angular2.dev.js:8080)
        在新PathLocationStrategy(router.dev.js:1203)
        在angular2.dev.js:1380
        在Injector._instantiate(angular2.dev.js:11923)
        在Injector._instantiateProvider(angular2.dev.js:11859)
        在Injector._new(angular2.dev.js:11849)
        在InjectorDynamicStrategy.getObjByKeyId(angular2.dev.js:11733)
        在Injector._getByKeyDefault(angular2.dev.js:12048)
        在Injector._getByKey(angular2.dev.js:12002)
        在Injector._getByDependency(angular2.dev.js:11990)

有谁知道为什么路由器扔呢?我使用angular2测试版

这是我的code:

进口{}组件从angular2 /核心;
进口{RouteConfig,ROUTER_DIRECTIVES}从'angular2 /路由器;
进口{} LoginComponent从'./pages/login/login.component';
从./pages/dashboard/dashboard.component进口{DashboardComponent};
@零件({
    选择:应用程序,
    指令:[ROUTER_DIRECTIVES]
    模板:`
        < D​​IV CLASS =包装>
            <路由器出口>< /路由器出口>
        < / DIV>`
})
@RouteConfig([
    {路径:'/',redirectTo:'/仪表盘},
    {路径:/登录,名称:'登陆',成分:LoginComponent},
    {路径:'/仪表盘,名称:仪表盘,部分:DashboardComponent,}
])
出口类AppComponent {
}


解决方案

https://angular.io/docs/ts/latest/guide/router.html

<base href="/">

Alternatively add

import {provide} from 'angular2/core';
import {APP_BASE_HREF} from 'angular2/router';

bootstrap(AppComponent, [
  ROUTER_PROVIDERS,
  provide(APP_BASE_HREF, {useValue : '/' });
]);

in your bootstrap.

这篇关于角2路由器没有基础的href集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-02 21:35
查看更多