Angular 2解析从外部CMS收到的链接是否可以解析为内部链接

时间:2017-09-26 13:10:45

标签: javascript angular2-routing angular2-template drupal-8 decoupling

我们正在开发一个分离项目,Drupal作为我们的后端,Angular作为我们的前端。一切都接近完成,但某些(动态,如在Drupal中创建的)页面需要链接到角度应用程序的不同页面。

例如:

  1. 编辑在Drupal中创建一个FAQ问题并给出答案 包含指向角度应用的定价页面的链接。 (问:这项服务的费用是多少?答:查看我们的[定价]页面)
  2. 前端用户打开常见问题解答页面
  3. Angular从Drupal通过REST加载我们的FAQ页面(html)
  4. 用户点击步骤1中提到的链接
  5. 会发生什么:

    重新加载整个页面,丢失当前正在进行的任何进程(即播放器中播放的内容),并让用户再次查看我们的加载屏幕。

    我们希望发生什么:

    我们希望触发路由器转到内部网址,这样我们就不会失去SPA的感觉。 我们尝试使用动态组件来复制它,但由于我们事先不知道内容是什么样的,因此很难实现它。

    是否有正式方法(或可能是解决方法)来解决这个问题?我们想象我们可以通过解析从CMS获得的任何链接,或者在我们的CKeditor中进行自定义格式化来解析。但是,一旦我们达到了有意义的一面,我们就不知道应该如何插入我们的HTML,而链接现在在内部工作。

1 个答案:

答案 0 :(得分:1)

自从您发布以来已经有一段时间了,但我自己没有找到解决方案,所以想要将其作为未来参考。

我们通过使用我们在html上使用的指令解决了这个问题:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// prototypes
int c_s(char*, char*);

struct sSheet
{
    char constab[30];
    char vicwit[15];
    char witdet[200];
    char incdest[300];
    char comp1[15];
    char comp2[200];
};
typedef struct sSheet sheetstore;

#define ARRAYLEN 2

sheetstore a[ARRAYLEN];


FILE *fp;

int main( void )
{
    int i;
    char wit[10] = "witness";
    //char yes[10] = "yes";
    char comp1[10];

    fp = fopen("sheetstore.dat","a+");
    if( !fp )
    {
        perror( "fopen for appending to 'sheetstore.dat' failed" );
        exit( EXIT_FAILURE );
    }

    // implied else, fopen successful

    puts("Hate crime reporting system\n\n\n");

    puts("If the crime you are reporting is an emergency,\n"
         "please call 999, "
         " do not proceed any further with this form\n\n\n\n"
         "Please press enter"
         " to confirm you have read the above and continue\n");
    int enter = 0;

    while (enter != '\r' && enter != '\n')
    {
        enter = getchar();
    }

    for( i=0; i<ARRAYLEN ; i++)
    {
        puts("Which police constabulary did the offence take place in?\n\n");
        if( scanf("%29s", a[i].constab) != 1)
        {
            fprintf( stderr, "scanf for which police constabulary failed" );
            fclose( fp );  // cleanup
            exit( EXIT_FAILURE );
        }

        // implied else, scanf successful

指令捕获所有点击并检查目标是否为带有href元素的标记。如果href是相对的,请使用路由器。如果它包含主机名(设置您自己的主机名),它将获取路径并使用路由器。否则它将在新窗口中打开。

<div [innerHTML]='contentFromCMS' appRouteDirective></div>