redirect-module icon indicating copy to clipboard operation
redirect-module copied to clipboard

feat(module): leverage vue-router redirect

Open ricardogobbosouza opened this issue 5 years ago • 13 comments

I put new properties in the path and redirect rules because the redirection done by the vue-router is different so the user can customize it if necessary.

For example, vue-router does not accept ^/abc in spa mode, but in universal mode this is acceptable, in spa mode /abc/(:id) this is acceptable, no longer in universal mode.

This /abc redirection per example is acceptable in both modes.

Resolve #3

ricardogobbosouza avatar Mar 21 '19 15:03 ricardogobbosouza

Codecov Report

:exclamation: No coverage uploaded for pull request base (master@4000dc7). Click here to learn what that means. The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##             master    #37   +/-   ##
=======================================
  Coverage          ?   100%           
=======================================
  Files             ?      2           
  Lines             ?     37           
  Branches          ?      9           
=======================================
  Hits              ?     37           
  Misses            ?      0           
  Partials          ?      0
Impacted Files Coverage Δ
lib/module.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 4000dc7...f6dcff5. Read the comment docs.

codecov[bot] avatar Mar 21 '19 15:03 codecov[bot]

Thanks so far! I wouldn't differentiate between SPA and universal mode. Instead, I'd check whether there is a server running or not (which makes the difference of having serverMiddleware handling everything or 'falling back' to the vue-router).

manniL avatar Mar 21 '19 15:03 manniL

Could you give me an example of how you're thinking?

ricardogobbosouza avatar Mar 21 '19 16:03 ricardogobbosouza

@manniL if change

if (this.options.mode === 'spa') {

to

this.nuxt.hook('generate:before', () => {

What I tested would solve the problem well.

ricardogobbosouza avatar Mar 25 '19 14:03 ricardogobbosouza

@ricardogobbosouza but then the extended route isn't included in the build bundle / .nuxt/router.js I think.

manniL avatar Mar 25 '19 17:03 manniL

@manniL It worked perfectly with the test I did local

ricardogobbosouza avatar Mar 25 '19 19:03 ricardogobbosouza

I will work on this change and its tests, but we will still have that divergence:

  • vue router using path-to-regexp that syntaxically/contextually different from js regex , if we don't move to that and take argument in the same form, it would be difficult to keep route working when 'proxying' to it. https://github.com/nuxt-community/redirect-module/issues/3#issuecomment-430624167

ricardogobbosouza avatar Mar 25 '19 19:03 ricardogobbosouza

Hmm... right. 🤔 We should make that clear in the README I guess.

manniL avatar Mar 27 '19 08:03 manniL

@manniL The only way to work in both cases is to use path-to-regexp on the serverMiddleware, the same as vue-router uses and this should probably generate BREAKING CHANGE

What do you think of switching to path-to-regexp ?

ricardogobbosouza avatar Mar 27 '19 11:03 ricardogobbosouza

Or do we create different options for the vue-router case as I said earlier https://github.com/nuxt-community/redirect-module/pull/37#issue-263278747

ricardogobbosouza avatar Mar 27 '19 11:03 ricardogobbosouza

What do you think of switching to path-to-regexp ?

I wrote a serverMiddleware which redirects using path-to-regexp: https://github.com/nuxt-community/redirect-module/issues/77#issuecomment-622328769

iliyaZelenko avatar May 04 '20 08:05 iliyaZelenko

Hi guys! Is it abandoned? Seems like that without this feature, the module is useless. If only i could help to push it forward?

fliptheweb avatar Mar 25 '22 18:03 fliptheweb

Due to lack of maintenance I forked that repo with merged client routing (thanks @ricardogobbosouza !) https://github.com/Bravado-network/nuxt-redirects

What I also added:

  • permanent: true instead of 301/302 status code (like in next.js redirects) to avoid confusion and mistakes;
  • path-to-regexp instead of 2 different scheme for client and server;
  • redirect to external urls;

fliptheweb avatar Apr 11 '22 16:04 fliptheweb