Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用typescript函数的Angular 6路由_Javascript_Typescript_Svg_Routing_Angular6 - Fatal编程技术网

Javascript 使用typescript函数的Angular 6路由

Javascript 使用typescript函数的Angular 6路由,javascript,typescript,svg,routing,angular6,Javascript,Typescript,Svg,Routing,Angular6,我试图以编程方式通过函数进行路由,因为当单击svg中的链接(标记)时(因为routerLink)不起作用,我需要一种解决方法 到目前为止,这就是我所拥有的: <g id="MenuStub4"> <path id="box" fill="#231F20" d="M1171.088,420.473c0,4.307-4.387,7.799-9.795,7.799h-94.15c-5.408,0-9.793-3.49

我试图以编程方式通过函数进行路由,因为当单击svg中的链接(标记)时(因为routerLink)不起作用,我需要一种解决方法

到目前为止,这就是我所拥有的:

    <g id="MenuStub4">
      <path
        id="box"
        fill="#231F20"
        d="M1171.088,420.473c0,4.307-4.387,7.799-9.795,7.799h-94.15c-5.408,0-9.793-3.492-9.793-7.799v-8.936
            c0-4.307,4.385-7.799,9.793-7.799h94.15c5.408,0,9.795,3.492,9.795,7.799V420.473z"
      />
      <text
        transform="matrix(1.3982 0 0 1 1096.8799 419.4614)"
        font-size="11.582"
      >
        <a fill="white" (click)="navigate()">
          Blog
        </a>
      </text>
    </g>
App-routing.module.ts:

import { BlogComponent } from './blog/blog.component';
import { NgModule, Component } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [{
  path: 'blog',
  component: BlogComponent
}];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }
我检查了路径,即使我用“/blog”更改它,它仍然不起作用


我是angular的noobie,因此我不确定我是否正确设置了路由,或者是否有其他错误。

如果你的应用程序routing.module.ts表示如下内容:

const routes:routes=[{
路径:“博客”,
组件:BlogComponent
}];

如果要在typescript中导航,请尝试以下操作:

this.router.navigate(['/blog'])


您不能将routerLink放在svg中,所以不要尝试这样做。

您是说app-routing.module.ts吗?我将在上面的问题中输入它的外观谢谢你的回答我想你已经了解了一些事情我将它添加到应用程序路由中,[routerlink]在svg中也不起作用“无法绑定到'href',因为它不是一个已知的属性::svg:a”。“好的,我做了路由,实际的链接会转到,但博客页面不会显示。”
import { BlogComponent } from './blog/blog.component';
import { NgModule, Component } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [{
  path: 'blog',
  component: BlogComponent
}];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }