小编ndg*_*eek的帖子

获取Angular中的当前URL

如何在AngularJS 4中获取当前URL?我在网上搜索了很多,但无法找到解决方案.

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule, Router } from '@angular/Router';

import { AppComponent } from './app.component';
import { TestComponent } from './test/test.component';
import { OtherComponent } from './other/other.component';
import { UnitComponent } from './unit/unit.component';

@NgModule ({
  declarations: [
    AppComponent,
    TestComponent,
    OtherComponent,
    UnitComponent
  ],

  imports: [
    BrowserModule,
    RouterModule.forRoot([
        {
            path: 'test',
            component: TestComponent
        },
        {
            path: 'unit',
            component: UnitComponent
        },
        {
            path: 'other',
            component: OtherComponent
        }
    ]),
  ],

  providers: …
Run Code Online (Sandbox Code Playgroud)

javascript url-routing typescript angular

101
推荐指数
3
解决办法
22万
查看次数

标签 统计

angular ×1

javascript ×1

typescript ×1

url-routing ×1