加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular2路由器:将URL标签添加到url

发布时间:2020-12-17 07:09:19 所属栏目:安全 来源:网络整理
导读:我正在使用Angular2 Seed应用程序,您可以在 official repo中找到它.正如您所看到的,这里我们已经导入了angular2 / router,我们正在使用它来创建应用程序的基本路由. import {Component,ViewEncapsulation} from 'angular2/angular2';import { RouteConfig,RO
我正在使用Angular2 Seed应用程序,您可以在 official repo中找到它.正如您所看到的,这里我们已经导入了angular2 / router,我们正在使用它来创建应用程序的基本路由.

import {Component,ViewEncapsulation} from 'angular2/angular2';
import {
  RouteConfig,ROUTER_DIRECTIVES
} from 'angular2/router';
...
@RouteConfig([
  { path: '/',component: HomeCmp,as: 'Home' },{ path: '/about',component: AboutCmp,as: 'About' }
])
export class AppCmp {}

我的问题是:如何配置路由器在我的网址中添加主题标签,使其看起来像:localhost:5555 /#/ about.有没有美丽而简单的方法来制作它? (与之前的$locationProvider一样)

我知道这很奇怪,但我曾经在网址中喜欢这个标签,而我的apache-config也曾经喜欢它.当然,我可以更改我的httpd.conf文件,非常简单和正确,但我真的想弄清楚,如何简单地添加hashtag,与Angular2路由器.

解决方法

在您的应用程序启动文件中,您需要在调用bootstrap时提供locationstrategy,

import {LocationStrategy,HashLocationStrategy} from 'angular2/router';

class MyDemoApp {
    //your code
}

bootstrap(MyDemoApp,[provide(LocationStrategy,{useClass: HashLocationStrategy})]);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读