A
A
Alexey Sobolenko2018-04-04 22:59:54
Regular Expressions
Alexey Sobolenko, 2018-04-04 22:59:54

How to implement an external link confirmation page in a single page application with Vue.js?

The blog is written in Vue.js. Blog posts will contain links to external resources. You need to make a page that will contain the following information:
"You are following an external link. If you do not want to wait, then click here. If you do not want to go, then click there, otherwise after 10 seconds you will go there automatically."
The text of the post in the editor is formatted using the BB code, which is then translated into html tags. External links take the form of text .
Here is an excerpt from the function that translates the BB code into html tags:

// BB-код
$in = array(
   ...
   '/\[url\="?(.*?)"?\](.*?)\[\/url\]/ms',
   ...
);
// html-теги
$out = array(
   ...
   '<a href="#/go/\1">\2</a>',
   ...
);
$text = preg_replace($in, $out, $text);

The question, in fact, is how to make vue-router accept them. Tried three options:
{ path: '/go/:p1/:p2/:p3/:p4/:p5/:p6/:p7/:p8/:p9/:p10', component: AppGoAway },
{ path: '/go/:link', component: AppGoAway },
{ path: '/go/', component: AppGoAway },

but none produced a result, and the link " /#/go/https://lenta.ru/news/2017/11/07/pochtagoda/ " is defined as a 404 error, falling under the options of this setting. Presumably my Vue settings are router fails because it sees multiple parameters after go in the link . Perhaps you should encode the url when translating a link from a BB code into html, but I'm not good at regular expressions. I took the translation function from the site of the markItUp editor.
{ path: '*', component: App404 }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2018-04-04
@alexsobolenko

But you can’t do it , but check $route.query in the AppGoAway component and, in general, fix $route? /go?link=http://elsewhere.com/blalba

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question