1

I'm a beginner for laravel an vuejs, when I am trying to refresh the page I got such error message, this is my code from web file :

Route::get('{path}',"HomeController@index")->where('path','(-a-z0-9_\s)');

Anyone with and idea?

KeitelDOG
  • 4,750
  • 4
  • 18
  • 33
  • What error do you get? – KeitelDOG Mar 03 '19 at 21:06
  • What URI are you trying to access that does not match your Regular Expression. If your URI does not match, then you'll get a Route Not Found exception. Try to remove Regex parenthesis. Try using https://regex101.com/ to validate your URI first to see if it finds a match – KeitelDOG Mar 03 '19 at 21:10
  • Possible duplicate of [preg\_match(): Compilation failed: invalid range in character class at offset](https://stackoverflow.com/questions/24764212/preg-match-compilation-failed-invalid-range-in-character-class-at-offset) – miken32 May 09 '19 at 22:26

2 Answers2

1

From looking at you Regular Expression, even it it compiled you probably won't find any URI that matches it, so you will get Laravel No Route exception.

You should probably use Brackets [] to setup the range of character and add the + to match that range multiple times to make words or phrase. Use this Regex :

[-a-z0-9_\s]+

The Route codes :

Route::get('{path}',"HomeController@index")->where('path','[-a-z0-9_\s]+');

Or use Brackets inside the Parenthesis :

Route::get('{path}',"HomeController@index")->where('path','([-a-z0-9_\s]+)');

Use https://regex101.com/ to validate your string with Regex the next time

KeitelDOG
  • 4,750
  • 4
  • 18
  • 33
0

you just need to change your code like this

Route::get('{path}',"HomeController@index")->where('path','[-a-z0-9_\s]+');
ALPHA
  • 1,135
  • 1
  • 8
  • 18